API Test: How to test HTTP methods using Postman
In this tutorial I will show you what HTTP methods are and how to test them. The methods used in this article are: POST, PUT, GET, DELETE.
- POST is used to send data to a server to create a resource.
- PUT is used to send data to a server to update a resource.
- GET is used to fetch data from a specified resource.
- DELETE method deletes the specified resource.
Dummy API
This article is using dummy API server provided by DummyJSON.
API Request
POST
This method will send data to the resource and create a new product called “BMW Pencil”. To do that in Postman, just create new request, ensure the method is POST, Insert the URL of the endpoint. In this simulation, the URL is “https://dummyjson.com/products/add”. In the Body tab, choose “raw” button and choose JSON, and then type:
{
"title": "BMW Pencil"
}
- Request
To make request using Curl you can see the following code. Just import the curl to Postman.
curl --location --request POST 'https://dummyjson.com/products/add' \
--header 'Content-Type: application/json' \
--data-raw '{
"title": "BMW Pencil"
}'
- Response
After all necessary parameter is fulfilled, click “Send” button, then we’ll get following response body.
{
"id": 101,
"title": "BMW Pencil"
}
PUT
This method will send data to the resource and update a product “1” and change the title into new value “iPhone Galaxy +1”. To do that in Postman, just create new request, ensure the method is PUT, Insert the URL of the endpoint. In this simulation, the URL is “https://dummyjson.com/products/1”. In the Body tab, choose “raw” button and choose JSON, and then type:
{
“title”: “iPhone Galaxy +1”
}
- Request
To make request using Curl you can see the following code. Just import the curl to Postman.
curl — location — request PUT ‘https://dummyjson.com/products/1' \
--header ‘Content-Type: application/json’ \
--data-raw ‘{
“title”: “iPhone Galaxy +1”
}’
- Response
After all necessary parameter is fulfilled, click “Send” button, then we’ll get following response body.
{
“id”: “1”,
“title”: “iPhone Galaxy +1”,
“price”: 549,
“stock”: 94,
“rating”: 4.69,
“images”: [
“https://dummyjson.com/image/i/products/1/1.jpg",
“https://dummyjson.com/image/i/products/1/2.jpg",
“https://dummyjson.com/image/i/products/1/3.jpg",
“https://dummyjson.com/image/i/products/1/4.jpg",
“https://dummyjson.com/image/i/products/1/thumbnail.jpg"
],
“thumbnail”: “https://dummyjson.com/image/i/products/1/thumbnail.jpg",
“description”: “An apple mobile which is nothing like apple”,
“brand”: “Apple”,
“category”: “smartphones”
}
GET
This method will fetch phone data from the resource. To do that in Postman, just create new request, ensure the method is GET, Insert the URL of the endpoint. In this simulation, the URL is “https://dummyjson.com/products/search?q=phone”.
- Request
To make request using Curl you can see the following code. Just import the curl to Postman.
curl --location --request GET 'https://dummyjson.com/products/search?q=phone'
- Response
After all necessary parameter is fulfilled, click “Send” button, then we’ll get following response body.
{
"products": [
{
"id": 1,
"title": "iPhone 9",
"description": "An apple mobile which is nothing like apple",
"price": 549,
"discountPercentage": 12.96,
"rating": 4.69,
"stock": 94,
"brand": "Apple",
"category": "smartphones",
"thumbnail": "...",
"images": ["...", "...", "..."]
},
{...},
{...},
{...}
// 4 results
],
"total": 4,
"skip": 0,
"limit": 4
}
DELETE
This method will DELETE data with product id “1” from the resource. To do that in Postman, just create new request, ensure the method is DELETE, Insert the URL of the endpoint. In this simulation, the URL is “https://dummyjson.com/products/1”.
- Request
To make request using Curl you can see the following code. Just import the curl to Postman.
curl — location — request DELETE ‘https://dummyjson.com/products/1'
- Response
After all necessary parameter is fulfilled, click “Send” button, then we’ll get following response body.
{
"id": 1,
"title": "iPhone 9",
"description": "An apple mobile which is nothing like apple",
"price": 549,
"discountPercentage": 12.96,
"rating": 4.69,
"stock": 94,
"brand": "Apple",
"category": "smartphones",
"thumbnail": "...",
"images": ["...", "...", "..."],
"isDeleted": true,
"deletedOn": /* ISOTime */
}
Follow me on
Facebook: https://www.facebook.com/mydoqa/
Instagram: https://www.instagram.com/mydoqa/
Twitter: https://twitter.com/MydoQa