Basic API Testing Interview Questions with Answers
In this article, we will discuss the Basic API Testing
Interview Questions that are frequently asked in interviews.
What are HTTP methods you have used in API Testing?
Generally we use the following HTTP methods in API Testing:- GET: used to fetch the data from the API
- POST: used to create a new resource
- PUT: used to update the existing resource
- PATCH: used to update the partial resource
- DELETE: used to delete the resource
- HEAD: used to fetch the headers of the resource
- OPTIONS: used to fetch the supported methods of the resource
- TRACE: used to fetch the path of the resource
What are the common status codes in API Testing?
Some of the common status codes in API Testing are:- 200: OK - The request was successful and the response is returned
- 201: Created - The request was successful and a new resource was created
- 400: Bad Request - The request was invalid
- 401: Unauthorized - The request requires user authentication or the user is not authenticated
- 403: Forbidden - The request is not allowed because the user does not have permission
- 404: Not Found - The resource was not found
- 500: Internal Server Error - The server has encountered an error and cannot process the request
What is the difference between query param and path param?
Query param is sent as key-value pairs in the URL after the ? symbol. For example, inhttps://api.example.com/users?id=123
, id
is the query param.
But the path param is sent as a part
of the URL itself. For example, in https://api.example.com/users/123
123
is the path param.
How to make API accept XML and return XML?
To make an API accept XML and return XML, we need to set the Content-Type and Accept headers in the request and response.For example, to make an API accept XML, we need to set the Content-Type header to application/xml in the request. And to make an API return XML, we need to set the Accept header to application/xml in the response.
What is the difference between Get and Post methods?
GET and POST are two different HTTP methods used in API Testing. The main differences between GET and POST are:GET | POST |
---|---|
Data is sent as query parameters in URL | Data is sent in request body |
Limited data can be sent due to URL length is limited | Large amount of data can be sent |
Data is visible in browser URL | Data is not visible in browser URL instead sent in request body masked |
Can be bookmarked | Cannot be bookmarked |
Less secure as data is visible in URL | More secure as data is not visible in URL and sent in request body |
Idempotent (multiple requests produce same result) | Non-idempotent (multiple requests may produce different results) |
What is the difference between PUT and POST methods?
The main differences between PUT and POST are:PUT | POST |
---|---|
Used to update the existing resource | Used to create a new resource |
Requires the entire resource to be sent in the request | Requires only the fields to be updated to be sent in the request |
Idempotent (multiple requests produce same result) | Non-idempotent (multiple requests may produce different results) |
What is the difference between PUT and PATCH methods?
The main differences between PUT and PATCH are:PUT | PATCH |
---|---|
Used to update the entire resource | Used to update the partial resource |
Requires the entire resource to be sent in the request | Requires only the fields to be updated to be sent in the request |
Idempotent (multiple requests produce same result) | Non-idempotent (multiple requests may produce different results) |
What is an Idempotent method?
An Idempotent method is a method that if we call the same method multiple times, it will produce the same result. In other words, the result of the method does not change with multiple calls. For example, GET and PUT are idempotent methods.What is a Non-idempotent method?
A Non-idempotent method is a method that if we call the same method multiple times, it will produce different results. In other words, the result of the method changes with multiple calls. For example, POST and DELETE are non-idempotent methods.What is the difference between SOAP and REST?
SOAP (Simple Object Access Protocol) and REST (Representational State Transfer) are two different types of web services used for communication between client and server.The main differences between SOAP and REST are:
SOAP | REST |
---|---|
SOAP is a protocol | REST is an architectural style |
SOAP uses XML format | REST uses JSON, XML, or other formats |
SOAP is more secure | REST is less secure |
SOAP is more rigid | REST is flexible |
SOAP requires more bandwidth | REST requires less bandwidth |
What are headers in API Testing?
Headers are the meta information that is sent along with the request and response in API Testing. Some of the common headers are:- Content-Type: specifies the type of data in the request or response
- Accept: specifies the type of data that the client can accept
- Authorization: specifies the authentication information
- User-Agent: specifies the information about the user agent
- Cache-Control: specifies the caching information
What is the difference between Request and Response in API Testing?
Request is the data that is sent from the client to the server in API Testing. It contains the HTTP method, URL, headers, and body.Whereas, Response is the data that is sent from the server to the client in API Testing. It contains the status code, headers, and body.
If you have liked our content, please share it with your friends
and colleagues.
Next up, we will discuss the Advanced
API
Testing Interview
Questions.