API Testing
API is a set of routines, protocols, and tools for building software applications. APIs specify how one software program should interact with other software programs.
In simple words, API stands for Application Programming Interface. API acts as an interface between two software applications and allows the two software applications to communicate with each other. API is a collection of software functions that can be executed by another software program
Examples of API Testing
A Google website can have API for various functions like search, translations, calendars, etc.
In general API’s are like below URL, they have the server name, paths.., etc
https://<server name>/v1/export/Publisher/Standard_Publisher_Report?format=csv
There are mainly 4 methods involve in API testing like the get, post, delete, and put methods.
GET- The GET method is used to extract information from the given server using a given URI. While using the GET request, it should only extract data and should have no other effect on the data.
POST- A POST request is used to create a new entity. It can also be used to send data to the server, for example, customer information, file upload, etc. using HTML forms.
PUT- Create a new entity or update an existing one.
DELETE- Removes all current representations of the target resource given by a URI.
API testing requires an application to interact with API. to test an API, you require two things,
- Testing tool/framework to drive the API
- Writing down your own code to test the API
Steps for testing rest API
Step 1: Launch the application e.g Postman, once it is installed successfully
Step 2: Enter the URL of the API in the URL textbox
Step 3: Select the method for the type of HTTP method to hit- e.g. Post
Step 4: Provide parameters, authorizations, headers pre-requisite scripts, and texts by entering the key and value pair, token for authorization, and body in XML, raw, body, or GRAPHQL formats
Now switch to Body Tab.
Set the required Body KEY AND VALUE e.G application/JSON
- Editor view: Raw input.
- Pass the request body of the API in the form of key-value pair e.g. {{“key1”:”value1",”key2":”value2"}. If it is post API, then we need to pass the body or parameters.
Step 5: Next is to click on SEND
Response Details
Summary
•An API or Application Programming Interface is a set of programming instructions for accessing a web-based software application.
•There are mainly 4 methods involve in API testing like GET, POST, DELETE, PUT methods
•We need to check the response code, response message, and response body in API testing.