AllMart Grocery Store API
Welcome to the AllMart Grocery Store API! This API allows you to fetch, filter, and interact with grocery product data. Below are the available endpoints and examples of how to use them.
View GitHub Repo
Endpoints
- GET /api/products - Fetch all products
- GET /api/products?category=fruit - Filter products by category
- GET /api/products?name=apple - Filter products by name
- GET /api/products?id=1 - Fetch a product by its unique ID
Query Parameters
- category - Filter products by category (e.g.,
?category=fruit)
- name - Filter products by name (e.g.,
?name=apple)
- id - Filter products by ID (e.g.,
?id=1)
Example API Call
This example fetches all products in the "fruit" category.
Response Example
This is an example of the JSON response you can expect from the API when fetching products.
Testing the API
You can test the API using tools like Postman, or by running the following script with Node.js:
This is an example of how to test the API using Node.js and Axios.
Notes
- Ensure you use the correct query parameters for filtering.
- All endpoints return JSON responses.
- If no products are found, the API will return a 404 error with an appropriate message.