Let's talk about widely used HTTP request methods and how to test them.
In this thread, we will cover:
- GET
- POST
- PUT
- DELETE
π§΅ππ»
π GET
The GET method is the widely used request method. It is used to get the desired resources from the server.
For example, making a request to the /posts endpoint will return all the available posts.
One thing to note here is that we have used plural noun (/posts) for URL naming.
Using plural nouns for naming URLs is the best practice. It simply reduces the confusion about whether there are one or more posts in the resource collection.
The GET method is safe, idempotent, and cacheable.
It doesn't affect the state of the server even after continuous calls. Also, we can cache the response of GET requests.
Here are a few points you need to validate for GET requests while creating tests for an API
- Server should return a 200 OK status code on a successful request
- Validate all endpoints and ensure they are returning desired data
π POST
The POST request is used to submit the information to the server. As we're submitting data, the POST request often changes the state of the server.
As POST request change the state of the server, it is not safe.
A POST request is not idempotent because successive POST calls may have additional effects on the server.
POST request is the second most common and widely used HTTP request method.
Here are some points you should consider while creating API tests
- 201 status code on a successful POST request
- Ensure data was saved correctly with a GET request
π PUT
The PUT request is used whenever you need to change the resource, which is already a part of resource collection.
The PUT request is idempotent, unlike POST. Successive PUT calls will always produce the same result.
But it is neither safe nor cacheable.
Ensure the following things when you create API tests for PUT requests
- Correct status codes are 200, 201, and 204
- Check idempotent characteristics by calling PUT methods successively
- Ensure the updated resource with the help of GET request
π DELETE
As the name says, the DELETE request is used to delete the specified resource. It requests that the origin server delete the resource identified by the Request-URL.
The DELETE request is idempotent but neither safe nor cacheable.
Steps for creating a test case for the DELETE method would look like this ππ»
- Create a resource using POST request. Let's say /posts
- Delete the created resources using /posts/id
- Ensure the 404 status with GET request
β’ β’ β’
Missing some Tweet in this thread? You can try to
force a refresh
Here are Top 5 Image Search and Image Recognition APIs you can use in your next project.
Thread π§΅ππ»
1οΈβ£ Imgur
- Imgur is an online image sharing and image hosting service. Imgurβs API exposes the entire Imgur infrastructure via a standardized programmatic interface.