APIs (Part 1)
Here are a few points you must know:
- All Web Services are APIs, but not all APIs are Web services.
- APIs are application interfaces, meaning that one application is able to interact with another application in a standardized way.
- Web services are a type of API, which must be accessed through a network connection.
- REST APIs are a standardized architecture for building web APIs using HTTP methods.
- Web service is a collection of open source protocols and standards used for exchanging data between systems or applications whereas API is a software interface that allows two applications to interact with each other without any user involvement.
- Web service is used for REST, SOAP and XML-RPC for communication while API is used for any style of communication.
- Web service supports only HTTP protocol whereas API supports HTTP/HTTPS protocol.
- Web service supports XML while API supports XML and JSON.
- All Web services are APIs but all APIs are not web services.
- Uploading file : .multiPart("file", new File(TestUtil.getFileURI("/examples/help.html")), "text/html")
GET - Path/Query params are provided to get response
PUT - Header, Body and Query params are provided to get the response
PATCH - Is used for updating without providing payload and only thing that needs to be updated
POST - Header, Body and Query params are provided to get the response
DELETE - Header, Body and Query params are provided to get the response
given().when().get("baseURI/resource").then().log().all()
given().queryParam("CUSTOMER_ID","68195")
.queryParam("PASSWORD","1234!")
.queryParam("Account_No","1") .when().get("http://demo.guru99.com/V4/sinkministatement.php").then().log()
.body();
RequestSpecification res;
ResponseSpecification resspec;
Response response;
TestDataBuild data =new TestDataBuild();
static String place_id;
//given:
RequestSpecification res=given().spec(requestSpecification()).body(data.addPlacePayLoad(name,language,address));
//when:
APIResources resourceAPI=APIResources.valueOf(resource);
ResponseSpecification resspec = new ResponseSpecBuilder().expectStatusCode(200).expectContentType(ContentType.JSON).build();
if(method.equalsIgnoreCase("POST"))
Response response =res.when().post(resourceAPI.getResource());
else if(method.equalsIgnoreCase("GET"))
Response response =res.when().get(resourceAPI.getResource());
//then:
assertEquals(response.getStatusCode(),200);
assertEquals(getJsonPath(response,keyValue),Expectedvalue);
place_id=getJsonPath(response,"place_id");
res=given().spec(requestSpecification()).queryParam("place_id",place_id);
user_calls_with_http_request(resource,"GET");
String actualName=getJsonPath(response,"name");
assertEquals(actualName,expectedName);
}