Rest API Interview Questions-3
Rest API Interview Questions-3
Ans. REST stands for Representational State Transfer. REST is an architectural style of
developing web services which take advantage of the ubiquity of HTTP protocol and leverages
HTTP method to define actions. It revolves around resource where every component is a
resource which can be accessed by a common interface using HTTP standard methods.
In REST architecture, a REST Server provides access to resources and REST client accesses and
presents those resources. Here each resource is identified by URIs or global IDs. REST uses
different ways to represent a resource like text, JSON, and XML.XML and JSON are the most
popular representations of resources these days.
What Is URI? Explain Its Purpose In REST Based Web Services. What
Is Its Format?
Ans. URI stands for Uniform Resource Identifier. URI is the identifier for the resource in REST
architecture.
The purpose of a URI is to locate a resource(s) on the server hosting the web service. A URI is of
the following format-
<protocol>://<service-name>/<ResourceType>/<ResourceID>
Example :
given().
parameters("firstName", "John", "lastName", "Doe").
when().
post("/greetXML").
then().
body("greeting.firstName", equalTo("John")).
body("greeting.lastName", equalTo("Doe"));
How to Insert cookies in Testing the API using Rest Assured?
given().cookie("username",
"John").when().get("/cookie").then().body(equalTo("username"));
given().header("MyHeader", "Something").
get("/x").then().assertThat().header("headerName", "headerValue").
given().auth().preemptive().basic("username",
"password").when().get("/secured/hello").then().statusCode(200);