Web Services and API
Web Services and API
What is an API?
API is the acronym for Application Programming Interface and it that allows two
applications to talk to each other. Each time you use an app like Facebook, send an instant
message, or check the weather on your phone, you’re using an API.
Location->Newyork
Radius->50
Key->
How to build rest request URL
1.What is the end point?
2.What are the types of rest request?
3.Headers and cookies?
End point->
1.BaseURL/Hostname-Website that we are trying to reach
2.Resource
3.Parameters
Endpoint->Baseurl/resource?Parameters
Baseurl/resource?Parameters
Weather.com/Weather?Location=newyork
1.Authentication
Session id
2.Content Type:
Plain text/XML/JSON
https://developers.google.com/places/web-service/search
Manual Testing tool for API’s
Postman- Postman is a Google Chrome app for interacting with HTTP APIs. It presents you
with a friendly GUI for constructing requests and reading responses.
https://developers.google.com/places/web-service/search
Resource: /place/nearbysearch/json
Parameters: ?location=-
33.8670522,151.1957362&radius=1500&type=restaurant&keyword=cruise&key= YOU
R_API_KEY
SWAPI API
Link : https://swapi.co/
Resources: /people/
Endpoint: https://swapi.co/api/people/
Employee API
http://dummy.restapiexample.com/
Get: http://dummy.restapiexample.com/api/v1/employees
http://dummy.restapiexample.com/api/v1/employee/{id}
Post: http://dummy.restapiexample.com/api/v1/create
{"name":"NextGen5","salary":"12345","age":"25"}
Put: dummy.restapiexample.com/api/v1/update/{id}
{"name":"NextGen6","salary":"12345","age":"25"}
Delete:
http://dummy.restapiexample.com/api/v1/delete/8597
Automation of Rest API’s
Rest API’s can be mainly automated using the
following Libraries in Robot framework
Request Library
HTTP Library
We will be covering HTTP Library since it has
more keywords
WebOb
Pip install WebTest
jsonpointer
pip install jsonpointer
jsonpatch
pip install jsonpatch
beautifulsoup
pip install beautifulsoup
HTTP library
pip install robotframework-httplibrary
HTTP Library Keywords
1. Create Http Context-
Sets the HTTP host to use for future requests.
host=None, scheme=http
2. GET
Issues a HTTP GET Request
url
3. Response Status Code Should Equal
Fails if the response status code of the previous request was not the specified one.
Status code
header_name
11. Response Should Not Have Header-
Header_name
12. Response Header Should Equal
Fails if the value of response header header_name does not equal expected. Also fails if
the last response does not have a header_nameheader.
Header,expected
13. Response Header Should Not Equal
14. PUT- Issues a http PUT Request
url
Example:
GET /foo.xml
Example:
GET /foo.xml
Set the target node of the JSON document json_string specified by JSON
Pointer json_pointer to json_value.
json_string, *args
Example:
${result}= Set Json Value {"foo": {"bar": [1,2,3]}} / 12
foo