Introduction to API Testing - Part 1


Introduction to API Testing - Part 1



A lot of times in our testing life cycle there comes to a situation when we need to quickly test our web-application or test it without any GUI (Graphical User Interface) in that case, API testing can help us a lot.

So in this Series of Blog, I will discuss all the aspects related to API Testing using Rest Assured-Framework.

So Let’s Get started with basic introduction and terminology that we will be using while testing doing API Testing.

What is Web Applications?

A Web Application is a software application that is deployed to a Web Server. This means the application is installed onto a computer and users access the application via a Web Browser.

The Web Application we will test has an API, which is a way of accessing the application without using a Web Browser or the application’s Graphical User Interface (GUI).




Google Is an Example of a Web Application

Google.com is an example of a Web Application. A user visits google.com in a Browser and the application’s Graphical User Interface (GUI) is displayed in the Browser. The GUI consists of a search input field which the user fills in and then clicks a button to search the Web.

When the user clicks the search button, the browser makes a request to the Web Application on the Web Server to have the Google Search Application make the search and return the results to the user in the form of a web page with clickable links.

When we first visit Google in a Browser we type in the URL or address for Google. i.e.  https://google.com

The browser then sends a type of HTTP request to Google called a GET request to ‘get’, or retrieve, the main search form. Google Web Application receives the request and replies with an HTTP response containing the HTML of the search page. HTML is the specification for the Web Page so the Browser knows how to display it to the user.

When the user types in a search term and presses the search button. The Browser sends a POST request to Google. The POST request is different from the GET request because it contains the details of the search term that the user wants the Google Web Application to Search for.

The Google Web Application then responds with an HTTP response that contains the HTML containing all the search results matching the User’s search term.


What is API?

An API is an Application Programming Interface. This is an interface to an application designed for other computer systems to use. As opposed to a Graphical User Interface (GUI) is designed for humans to use.

An HTTP based API is often called a Web API since they are used to access Web Applications that are deployed to Servers accessible over the Internet.

Applications which are accessed via HTTP APIs are often called Web Services.






What Is an HTTP Request?

HTTP stands for Hypertext Transfer Protocol and is a way of sending messages to software on another computer over the Internet or over a Network.

An HTTP request is sent to a specific URL and consists of:

• VERB specifying the type of request e.g. GET, POST, PUT, DELETE
• A set of HTTP Headers. The headers specify information such as the type of Browser,
type of content in the message, and what type of response is accepted in return.
• A body, or payload in the request, representing the information sent to, or from, the Web Application. Not all HTTP messages can have payloads: POST and PUT can have payloads, GET and DELETE can not.


What Is a URL?

URL is a Uniform Resource Locator and is the address we use to access websites and web applications.
When working with APIs you will often see this referred to as a URI (Uniform Resource Identifier).
Think of a URI as the generic name for a URL.

What Are HTTP Verbs?

A Web Browser will usually make GET requests and POST requests.

GET requests to ask to read information from the server e.g. clicking on a link.
POST requests supply information to the server e.g. submitting a form.
GET requests do not have a body, and just consist of the Verb, URL and the Headers.

When Working with Web Application or HTTP API the typical verbs used are :

GET- The GET method is used to extract information from the given server using a given URI. While using GET request, it should only extract data and should have no other effect on the data.

POST- A POST request is used to send data to the server, for example, customer information, file upload, etc. using HTML forms.

PUT- Replaces all current representations of the target resource with the uploaded content.

DELETE- Removes all current representations of the target resource given by a URI.



What Is an HTTP Response?

When you issue an HTTP Request to the server you receive an HTTP Response.
The response from the server tells you if your request was successful, or if there was a problem.

• A status code of 200, which means that the request was successful.
• A Content-Type header of application/JSON which means that the body is a JSON response.
• A body that contains the actual payload response from the server.


What Is an HTTP Status Code?

Web Services and HTTP APIs use HTTP Status Codes to tell us what happened when the server processed the request.

The simple grouping for HTTP Status Codes is:

• 1xx - Informational
• 2xx - Success e.g. 200 Success
• 3xx - Redirection e.g. 302 Temporary Redirect
• 4xx - Client Error e.g. 400 Bad Request, 404 Not Found
• 5xx - Server Error e.g. 500 Internal Server Error

The type of status code you receive depends on the application you are interacting with.
Usually a 4xx error means that you have done something wrong and a 5xx error means that something has gone wrong with the application server you are interacting with.

Please Refer to the Next blog to continue with few more basic terms related to API Testing.



SHARE THIS

Author:

My Name is Ankur Jain and I am currently working as Automation Test Architect.I am ISTQB Certified Test Manager,Certified UI Path RPA Developer as well as Certified Scrum Master with total 12 years of working experience with lot of big banking clients around the globe.I love to Design Automation Testing Frameworks with Selenium,Appium,Protractor,Cucumber,Rest-Assured, Katalon Studio and currently exploring lot in Dev-OPS as well. I am currently staying in Mumbai, Maharashtra. Please Connect with me through Contact Us page of this website.

Previous Post
Next Post
January 11, 2019 at 8:15 AM

Amazing blog Ankur. Keep up the good work ๐Ÿ‘

Reply
avatar
January 12, 2019 at 12:12 AM

Really very helpful to people like me who wsnwa to learn and explore new technology keep up the good work going ,you explanation is very understandable

Reply
avatar
May 2, 2019 at 1:39 PM

helpful blog for learning API testing!!

Reply
avatar
May 17, 2019 at 9:39 AM

Really helpful.At last a good site where I can get all info I need

Reply
avatar