Tricky interview questions about REST API testing

We have prepared a collection of interesting interview questions about REST API testing that you may encounter during a job interview for software testing positions.

Under each question, I have provided the correct answer. I encourage you to test the given solutions yourself to fully understand and remember them.

List of questions

  • What is the difference between PUT and PATCH?
  • Are the HTTP methods POST and DELETE idempotent?
  • Explain the concept of ‘statelessness’ in REST API and its importance for testing
  • How can you test an API without using tools (e.g., Postman)?
  • Can you name one difference between RESTful API and Event-Driven API?
  • Does a REST API always have to return JSON?
  • What happens if the PATCH method is used to update a non-existent resource?

List of answers

Classic interview question – what is the difference between PUT and PATCH?

The answer is short and to the point:

  • PUT is typically used for full resource updates, meaning the provided data should completely replace the existing resource data.
  • PATCH is used for partial updates, where only the fields that need to be changed are sent.

Are the HTTP methods POST and DELETE idempotent?

his is a somewhat tricky question because it assumes you know what idempotency means in the context of HTTP. Simply put, it means that regardless of the number of repetitions, the effect of the request remains the same.

DELETE: It is idempotent

Calling the DELETE method multiple times on the same resource has the same effect as calling it once—the resource is deleted or no longer exists.

POST: It is not idempotent

… because each call of this method can create a new resource or perform a different action, changing the server state every time.

Example: calling POST /users with user data may create a new user each time (e.g., with a unique ID).

Explain the concept of ‘statelessness’ in REST API and its importance for testing

Answer: Statelessness in REST API means that each client request to the server is independent and does not store information about previous requests. The server does not retain user session state, requiring all necessary data (e.g., authentication tokens) to be sent with each request.

What should we pay attention to during testing?

Each request must include all required data (e.g., authorization tokens, parameters), and tests should not rely on previous requests. Tests should verify whether the absence of this data results in the appropriate error (e.g., 401 Unauthorized).

How can you test an API without using tools (e.g., Postman)?

Answer: You can test an API using tools like curl. This command-line tool allows you to send various types of HTTP requests (GET, POST, PUT, DELETE) and analyze responses directly in the terminal.

Can you name one difference between RESTful API and Event-Driven API?

Example answer:

RESTful API is suitable for applications where interactions are based on operations on resources in response to specific user requests. RESTful APIs are synchronous, meaning each request waits for a response before proceeding further. For example, when purchasing something through an e-commerce app, each request (such as retrieving product prices or fetching cart contents) is processed and responded to sequentially.

Event-driven API is used in applications that require real-time reactions to changes in the system, where events trigger actions—e.g., financial apps (such as stock price tracking), IoT applications, and communication platforms. Communication is asynchronous. For example, during file upload, the server notifies the client when the upload is complete, allowing parallel continuation of other processes.

Does a REST API always have to return JSON?

The answer is: No, it doesn’t have to, although in practice, JSON is most commonly used because it is lightweight, easy to read by both humans and machines, and well-supported by many programming languages.

A REST API can return other data formats, such as XML or plain text.

What happens if the PATCH method is used to update a non-existent resource?

Answer: The server’s behavior when using the PATCH method for a non-existent resource may depend on the API implementation. However, the server typically returns an HTTP status code 404 (Not Found), indicating that the resource you are trying to update does not exist. Some implementations may treat PATCH as a ‘create or update’ operation and return a 201 (Created) status code in response.

Podobał Ci się ten artykuł?

Jeśli chciałbyś przeczytać takich więcej, zachęcamy do polubienia naszych profili w mediach społecznościowych. Zero spamu, sam konkret!

Leave a Comment