Products
Get and modify e-commerce products with HTTP methods.
Product object
Defines the structure of a product resource returned by the API.
{
"id": "integer",
"title": "string",
"price": "number <float>",
"description": "string",
"category": "string",
"image": "string",
"rating": {
"rate": "number <float>",
"count": "integer"
}
}
GET /products
Retrieve a list of product data from the Fake Store API.
Make request
-
Endpoint:
/products -
Method:
GET
Request:
curl https://fakestoreapi.com/products
Response:
-
Status:
200 OK -
Content-Type:
application/json
[
{
"id": 1,
"title": "Fjallraven - Foldsack No. 1 Backpack, Fits 15 Laptops",
"price": 109.95,
"category": "men's clothing",
"image": "https://fakestoreapi.com/img/81fPKd-2AYL._AC_SL1500_t.png",
"rating": {
"rate": 3.9,
"count": 120
}
}
]
GET /products/{id}
Retrieves a specific product by its ID.
Make request
-
Endpoint:
/products/{id} -
Method:
GET -
Path parameter:
id(integer)
Request
curl https://fakestoreapi.com/products/{id}
To fetch a product with an ID of 5, use:
curl https://fakestoreapi.com/products/5
Response
-
Status:
200 OK -
Content-Type:
application/json
{
"id": 5,
"title": "John Hardy Women's Naga Gold & Silver Dragon Station Chain Bracelet",
"price": 695,
"category": "jewelery",
"image": "https://fakestoreapi.com/img/71pWzhdJNwL._AC_UL640_QL65_ML3_t.png",
"rating": {
"rate": 4.6,
"count": 400
}
}
For non-existing or non-integer IDs, the API returns 200 OK with an empty response body.
POST /products
Adds a new product to the store.
Make request
-
Endpoint:
/products -
Method:
POST -
Headers:
Content-Type: application/json -
Request body:
{
"title": "Test sample",
"price": 500,
"category": "electronics",
"image": "https://exampleimage.com/img.png"
}
The id field is generated by the server and should not be included in the request body.
Request
curl -X POST https://fakestoreapi.com/products \
-H "Content-Type: application/json" \
-d '{"title": "Test sample", "price": 500, "category": "electronics","image": "https://exampleimage.com/img.png"}'
Response
-
Status:
201 Created -
Content-Type:
application/json
{
"id":21,
"title":"Test sample",
"price":500,
"image":"https://exampleimage.com/img.png",
"category":"electronics"
}
PUT /products/{id}
Updates an existing product by its ID.
Make request
-
Endpoint:
/products/{id} -
Method:
PUT -
Path parameter:
id(integer) -
Headers:
Content-Type: application/json -
Request body:
{
"title": "Test sample",
"price": 800,
"category": "jewelry",
"image": "https://exampleimage.com/img.png"
}
Request
curl -X PUT https://fakestoreapi.com/products/{id} \
-H "Content-Type: application/json" \
-d '{"title": "Test sample", "price": 800, "category": "jewelry","image": "https://exampleimage.com/img.png"}'
Replace {id} with a valid product ID:
curl -X PUT https://fakestoreapi.com/products/5 \
-H "Content-Type: application/json" \
-d '{"title": "Test sample", "price": 800, "category": "jewelry","image": "https://exampleimage.com/img.png"}'
The Fake Store API does not validate whether a product exists. Hence, it accepts any integer value and returns a successful JSON response.
Decimal values (for example, 7.5) are, however, coerced into integers before the product is updated.
Success response
-
Status:
200 OK -
Content-Type:
application/json
{
"id": 5,
"title": "Test sample",
"price": 800,
"category": "jewelry",
"image": "https://exampleimage.com/img.png"
}
The API response includes the specified product id and the fields provided in your request body.
Error response
The API returns a JSON-formatted error when the id path parameter is not a valid integer.
-
Status:
400 Bad Request -
Response:
{
"status": "error",
"message": "something went wrong! check your sent data"
}
DELETE /products/{id}
Simulates the removal of a product from the store by ID.
Make request
-
Endpoint:
/products/{id} -
Method:
DELETE -
Path parameter:
id(integer)
Request
curl -X DELETE https://fakestoreapi.com/products/{id}
To delete a product with an id of 2, use:
curl -X DELETE https://fakestoreapi.com/products/2
Response
-
Status:
200 OK -
Content-Type:
application/json
{
"id": 2,
"title": "Mens Casual Premium Slim Fit T-Shirts ",
"price": 22.3,
"category": "men's clothing",
"image": "https://fakestoreapi.com/img/71-3HjGNDUL._AC_SY879._SX._UX._SY._UY_t.png",
"rating": {
"rate": 4.1,
"count": 259
}
}
Error response
When the id inputted is not an integer, the API returns an error message.
- Status:
400 Bad Request
{
"status":"error",
"message":"product id should be provided"
}