Monday, April 21, 2014

How To test REST API using REST CLIENT .

How To Test REST API using REST CLIENT 

REST : REST (REpresentational State Transfer) is a simple stateless architecture that generally runs over HTTP. REST is simpler to use than the well-known SOAP (Simple Object Access Protocol) approach, which requires writing or using a provided server program (to serve data) and a client program (to request data). RESTful APIs are defined with these aspects:
·   base URI, such as http://example.com/resources/
·   an Internet media type for the data. This is often JSON but can be any other valid Internet media type (e.g. XML, Atom, microformats, images, etc.)

·    standard HTTP methods (e.g., GET, PUT, POST, or DELETE)
A sample format of the Rest API with payload and Request method defined as below

URL
Type/Method
Payload (Json)
Response
http://example.com/resources
POST
{
"wsTest": {
"Code": “abc",
"Name": "test",
"enabled": true,
}
}
http://example.com/resources/1
POST
{}
GET
?keywordcode=abc
{
"wsTest": {
"Code": “abc",
"Name": "test",
"enabled": true,
}
}

Rest API could be tested via REST client. Rest client is an addon which comes with Mozilla firefox .
You could also use chrome addon . Link to download restclient addon in chrome 

After installing RESTclient it will ask for the browser to restart .  REST client could be started by clicking on the icon top right corner of the Mozilla firefox browser .

The below snapshot shows the example of GET method 

Steps  > >

1.      Enter the URL / REST API to be tested in the URL field
2.       Select the HTTP method as GET
3.       Set content type to from drop down box .
4.       Click on send button
5.       Check the specified response in response box . can view response as text /JSON 
The below snapshot shows the example of POST method 
Steps  > >
1.       Enter the URL/REST API be tested in the URL field
2.       Select the HTTP method as POST
3.       Enter the JSON request as Payload  eg  :
{
    "noOfResults": 100,
    "start": 0,
    "columns": [
        "itemType",
        "productCode"
    ],
    "fetchResultCount": true,
}
4.       Set content type to from drop down box .
5.       Click on send button
6.       Check the specified response in response box . can view response as TEXT /JSON








No comments:

Post a Comment