|
| 1 | +# Product API Documentation |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This document outlines the implementation of the products API endpoints for the small and large datasets utilizing mock data. |
| 6 | + |
| 7 | +## Endpoints |
| 8 | + |
| 9 | +### 1. List Products |
| 10 | + |
| 11 | +**GET /api/products**: |
| 12 | +Retrieve a list of products with optional pagination and search functionality. |
| 13 | + |
| 14 | +**Query Parameters:** |
| 15 | + |
| 16 | +- limit (number, optional): Maximum number of products to return. |
| 17 | +- offset (number, optional): Number of products to skip before starting to collect the results. |
| 18 | +- search (number, optional): Query string to search for products name. |
| 19 | + |
| 20 | +Examples: |
| 21 | +**GET /api/products** to retrieve all products (be aware of the size of the dataset we're working with). |
| 22 | +**GET /api/products?limit=10&offset=20** to retrieve products with pagination (ignoring the first 20 and fetching the next 10). |
| 23 | +**GET /api/products?search=Awesome** to search for products starting with "Awesome". |
| 24 | +**GET /api/products?search=Awesome&limit=5&offset=10** to combine pagination with name searching. |
| 25 | + |
| 26 | +Response always returns a JSON array of product objects matching the criteria in this format: |
| 27 | + |
| 28 | +> |
| 29 | +
|
| 30 | + { |
| 31 | + "id":"82f5c990-fc36-4931-8678-8af71434ca47", |
| 32 | + "name":"Recycled Steel Chips", |
| 33 | + "price":"972.00", |
| 34 | + "description":"The automobile layout consists of a front-engine design...", |
| 35 | + "category":"Movies", |
| 36 | + "rating":1.9314758584368974, |
| 37 | + "numReviews":53, |
| 38 | + "countInStock":52 |
| 39 | + } |
| 40 | + |
| 41 | +--- |
| 42 | + |
| 43 | +### 2. Get Product by ID |
| 44 | + |
| 45 | +**GET /api/products/{id}**: |
| 46 | +Retrieves detailed information about a single product by its unique ID. |
| 47 | + |
| 48 | +**Path Parameters:** |
| 49 | + |
| 50 | +- {id} (string): The unique identifier of the product. |
| 51 | + |
| 52 | +Examples: |
| 53 | +**GET /api/products/82f5c990-fc36-4931-8678-8af71434ca47** to retrieve the product with the informed Id. |
| 54 | + |
| 55 | +Response returns a JSON object of the product in this format: |
| 56 | + |
| 57 | +> |
| 58 | +
|
| 59 | + { |
| 60 | + "id":"82f5c990-fc36-4931-8678-8af71434ca47", |
| 61 | + "name":"Recycled Steel Chips", |
| 62 | + "price":"972.00", |
| 63 | + "description":"The automobile layout consists of a front-engine design...", |
| 64 | + "category":"Movies", |
| 65 | + "rating":1.9314758584368974, |
| 66 | + "numReviews":53, |
| 67 | + "countInStock":52 |
| 68 | + } |
| 69 | + |
| 70 | +--- |
| 71 | + |
| 72 | +### Testing |
| 73 | + |
| 74 | +Ensure the application is running locally by executing `pnpm dev`. |
| 75 | +Use a browser. cURL or Postman for simple `GET` requests. |
| 76 | + |
| 77 | +**Cases:** |
| 78 | +List all products: `GET http://localhost:3000/api/products` |
| 79 | +List Products with Pagination: `GET http://localhost:3000/api/products?limit=10&offset=0` |
| 80 | +Search Products by Name: `GET http://localhost:3000/api/products?search=Awesome` |
| 81 | +Combined Pagination and Search: `GET http://localhost:3000/api/products?search=Pro&limit=5&offset=0` |
| 82 | +Get Product by ID: `GET GET http://localhost:3000/api/products/82f5c990-fc36-4931-8678-8af71434ca47` |
0 commit comments