API in simple words is bridge between 2 applications. an simple example of an API is when we book an rail ticket from any platform (Amazon or Paytm) we have noticed that after entering the user details it redirect us to the IRCTC website. so here that process which negivate us to the IRCTC is done threw the API.
There are types of API:
1) SOAP API
2) Rest API
now, to validate any API there are many tools available in market like postman, or swagger. but here i am showing you an example how can we automate Rest API using Rest Assured.
To create a setup there is 3 steps which we need to follow
1) Create and Maven Project (File > New > Others > Maven project)
Step 2 : After creating Maven project. go to the pom.xml file and add these dependencies in it
Add these dependencies in pom.xml file in dependencies tag
password for this file : 11223344
Step 3 : After creating maven project and adding these dependencies in project, create an TestNG class.
Now, after creating setup first thing we need to do is to setup and base URI of the API
@Test public void getData() { RestAssured.baseURI="https://restcountries.eu/rest/v2/alpha/";
//creating request object RequestSpecification request = RestAssured.given(); //creating response object Response response = request.request(Method.GET,"ind");
String responsedata=response.getBody().asString(); System.out.println("Request data is==> "+responsedata); int status_code=response.getStatusCode(); System.out.println("response code is==>"+status_code);
No comments:
Post a Comment