Notes Download
End point: Address where API is hosted on the Server.
HTTP methods which are commonly used to communicate with Rest API�s are
GET, POST, PUT, and DELETE,PATCH
GET- The GET method is used to extract information from the given server using a
given URI. While using GET request, it should only extract data and should have no
other effect on the data. No Payload/Body required
How to send input data in GET?
Ans: Using Query Parameters
POST- A POST request is used to send data to the server, for example, customer
information, file upload, etc. using HTML forms.
How to send input data in POST?
Ans: Using Form Parameters /Body Payload
PUT- Replaces all current representations of the target resource with the uploaded
content.
DELETE- Removes all current representations of the target resource given by a URI.
Resources:
Resources represent API/Collection which can be accessed from the Server
Google.com/maps
google.com/search
google.com/images
Path Parameters:
Path parameters are variable parts of a URL path. They are typically used to point
to a specific resource within a collection, such as a user identified by ID
https://www.google.com/Images/1123343
https://www.google.com/docs/1123343
https://amazon.com/orders/112
https://www.google.com/search?
q=newyork&oq=newyork&aqs=chrome..69i57j0l7.2501j0j7&sourceid=chrome&ie=UTF-8
Query Parameters:
Query Parameter is used to sort/filter the resources.
Query Parameters are identified with?
https://amazon.com/orders?sort_by=2/20/2020
Headers/Cookies:
Headers represent the meta-data associated with the API request and response. In
layman terms, we were sending Additional details to API to process our request.
Example : Authorization details
End Point Request URL can be constructed as below
Base URL/resource/(Query/Path)Parameters
------------------
Maven Dependencies in POM.XMl
1. Rest assured
2. TestNG
3. Hamcrest
------------------
Rest Assured works on 3 principles
Given ---Give all the input details(base URI ,query/path parameters, header)
When ---Submit the the api( type of HTTP method(get or post update ,delete) and
resource type (End point)
Then --validate the response (assert methods, statuscode)
-------------------
Eclipse will convert json to string format which java accept. When you paste json
content in body method
-----------
Log() all() method used to give clear logs about concatenation of HTTP requests,
input and output logs
Examples:
1.given().log().all().queryParam("key", "qaclick123").header("Content-
Type","application/json")
2.then().log().all().assertThat().statusCode(200);
In the Mock response-- when development is not completed . I need to validate the
response of the API . Once the API developed will hit the real api call.
Json file :
"dashboard": {
"purchaseAmount": 910,
"website": "rahulshettyacademy.com"
},
"courses": [
"title": "Selenium Python",
"price": 50,
"copies": 6
},
"title": "Cypress",
"price": 40,
"copies": 4
},
"title": "RPA",
"price": 45,
"copies": 10
-----
1. Print No of courses returned by API
2. Print Purchase Amount
3. Print Title of the first course
4. Print All course titles and their respective Prices
5. Print no of copies sold by RPA Course
6. Verify if Sum of all Course prices matches with Purchase Amount
----