### Fetch All Products (JavaScript) Source: https://dummyjson.com/docs/products Retrieves all products from the API. By default, it returns 30 items. The 'limit' and 'skip' parameters can be used for pagination. This example uses the fetch API to get the data and logs the JSON response. ```javascript fetch('https://dummyjson.com/products') .then(res => res.json()) .then(console.log); ``` -------------------------------- ### Paginate and Select Product Data (JavaScript) Source: https://dummyjson.com/docs/products Fetches products with specified limits and skips for pagination, and selects specific fields using the 'select' parameter. This allows for efficient data retrieval by only getting necessary fields. The example uses the fetch API. ```javascript fetch('https://dummyjson.com/products?limit=10&skip=10&select=title,price') .then(res => res.json()) .then(console.log); ``` -------------------------------- ### Fetch Posts by User ID (JavaScript) Source: https://dummyjson.com/docs/posts Fetches all posts created by a specific user ID from the DummyJSON API. This example demonstrates a GET request to the user posts endpoint. The response contains an array of posts, the total number of posts, and pagination details. ```javascript /* getting posts by user with id 5 */ fetch('https://dummyjson.com/posts/user/5') .then(res => res.json()) .then(console.log); ``` -------------------------------- ### GET /products/search Source: https://dummyjson.com/docs/products Searches for products based on a query string. ```APIDOC ## GET /products/search ### Description Searches for products that match a given query string. The search is performed across product titles and descriptions. ### Method GET ### Endpoint `/products/search` ### Query Parameters - **q** (string) - Required - The search query string. ### Request Example ``` fetch('https://dummyjson.com/products/search?q=phone') .then(res => res.json()) .then(console.log); ``` ### Response #### Success Response (200) - **products** (array) - An array of product objects matching the search query. - **total** (integer) - The total number of products found. - **skip** (integer) - The number of products skipped (usually 0 for search results). - **limit** (integer) - The maximum number of products returned in the search results. #### Response Example ```json { "products": [ { "id": 101, "title": "Apple AirPods Max Silver", "category": "mobile-accessories" // ... other product details } // ... more matching products ], "total": 23, "skip": 0, "limit": 23 } ``` ``` -------------------------------- ### Get All Product Categories Source: https://dummyjson.com/docs/products Retrieves a list of all available product categories. ```APIDOC ## GET /products/categories ### Description Fetches a list of all available product categories, including their slug, name, and a URL to access products within that category. ### Method GET ### Endpoint `/products/categories` ### Response #### Success Response (200) - **categories** (array) - An array of category objects, each containing 'slug', 'name', and 'url'. #### Response Example ```json [ { "slug": "beauty", "name": "Beauty", "url": "https://dummyjson.com/products/category/beauty" }, { "slug": "fragrances", "name": "Fragrances", "url": "https://dummyjson.com/products/category/fragrances" } // ... more categories ] ``` ``` -------------------------------- ### Get Product Category List Source: https://dummyjson.com/docs/products Retrieves a simple list of all product category names. ```APIDOC ## GET /products/category-list ### Description Fetches a simple array containing the names of all available product categories. ### Method GET ### Endpoint `/products/category-list` ### Response #### Success Response (200) - **categoryList** (array) - An array of strings, where each string is a product category name. #### Response Example ```json [ "beauty", "fragrances", "furniture", "groceries" // ... more categories ] ``` ``` -------------------------------- ### GET /products/{id} Source: https://dummyjson.com/docs/products Retrieves a single product by its unique ID. ```APIDOC ## GET /products/{id} ### Description Retrieves the details of a specific product using its unique identifier. ### Method GET ### Endpoint `/products/{id}` ### Path Parameters - **id** (integer) - Required - The unique identifier of the product. ### Request Example ``` fetch('https://dummyjson.com/products/1') .then(res => res.json()) .then(console.log); ``` ### Response #### Success Response (200) - **id** (integer) - The unique identifier of the product. - **title** (string) - The name of the product. - **description** (string) - A detailed description of the product. - **category** (string) - The category the product belongs to. - **price** (number) - The price of the product. - **discountPercentage** (number) - The discount percentage applied to the product. - **rating** (number) - The average rating of the product. - **stock** (integer) - The number of items in stock. - **tags** (array) - An array of tags associated with the product. - **brand** (string) - The brand of the product. - **sku** (string) - The Stock Keeping Unit (SKU) of the product. - **weight** (integer) - The weight of the product. - **dimensions** (object) - The dimensions of the product (width, height, depth). - **warrantyInformation** (string) - Information about the product's warranty. - **shippingInformation** (string) - Information about the product's shipping. - **availabilityStatus** (string) - The current availability status of the product. - **reviews** (array) - An array of reviews for the product. - **returnPolicy** (string) - The return policy for the product. - **minimumOrderQuantity** (integer) - The minimum order quantity for the product. - **meta** (object) - Metadata about the product (createdAt, updatedAt, barcode, qrCode). - **thumbnail** (string) - URL to the product's thumbnail image. - **images** (array) - An array of URLs to the product's images. #### Response Example ```json { "id": 1, "title": "Essence Mascara Lash Princess", "description": "The Essence Mascara Lash Princess is a popular mascara known for its volumizing and lengthening effects. Achieve dramatic lashes with this long-lasting and cruelty-free formula.", "category": "beauty", "price": 9.99, "discountPercentage": 7.17, "rating": 4.94, "stock": 5, "tags": [ "beauty", "mascara" ], "brand": "Essence", "sku": "RCH45Q1A", "weight": 2, "dimensions": { "width": 23.17, "height": 14.43, "depth": 28.01 }, "warrantyInformation": "1 month warranty", "shippingInformation": "Ships in 1 month", "availabilityStatus": "Low Stock", "reviews": [ { "rating": 2, "comment": "Very unhappy with my purchase!", "date": "2024-05-23T08:56:21.618Z", "reviewerName": "John Doe", "reviewerEmail": "john.doe@x.dummyjson.com" } // ... more reviews ], "returnPolicy": "30 days return policy", "minimumOrderQuantity": 24, "meta": { "createdAt": "2024-05-23T08:56:21.618Z", "updatedAt": "2024-05-23T08:56:21.618Z", "barcode": "9164035109868", "qrCode": "..." }, "thumbnail": "...", "images": ["...", "...", "..."] } ``` ``` -------------------------------- ### GET /posts/tags Source: https://dummyjson.com/docs/posts Retrieves a list of all available post tags. ```APIDOC ## GET /posts/tags ### Description Retrieves a list of all available post tags. ### Method GET ### Endpoint /posts/tags ### Response #### Success Response (200) - **tags** (array) - An array of tag objects, each containing slug, name, and URL. #### Response Example ```json [ { "slug": "history", "name": "History", "url": "https://dummyjson.com/posts/tag/history" }, { "slug": "american", "name": "American", "url": "https://dummyjson.com/posts/tag/american" } // ... more tags ] ``` ``` -------------------------------- ### GET /products Source: https://dummyjson.com/docs/products Retrieves a list of all products. By default, it returns 30 items. Use 'limit' and 'skip' parameters for pagination, and 'select' to specify fields. ```APIDOC ## GET /products ### Description Retrieves a list of all products. Supports pagination using `limit` and `skip` parameters, and field selection with the `select` parameter. ### Method GET ### Endpoint `/products` ### Query Parameters - **limit** (integer) - Optional - The maximum number of products to return. Use `limit=0` to get all items. - **skip** (integer) - Optional - The number of products to skip from the beginning of the list. - **select** (string) - Optional - A comma-separated list of fields to include in the response. ### Request Example ``` fetch('https://dummyjson.com/products?limit=10&skip=10&select=title,price') .then(res => res.json()) .then(console.log); ``` ### Response #### Success Response (200) - **products** (array) - An array of product objects. - **total** (integer) - The total number of products available. - **skip** (integer) - The number of products skipped. - **limit** (integer) - The limit of products returned. #### Response Example ```json { "products": [ { "title": "Essence Mascara Lash Princess", "price": 9.99 }, { "title": "", "price": "" } // ... more products ], "total": 194, "skip": 10, "limit": 10 } ``` ``` -------------------------------- ### Get IP Address Source: https://dummyjson.com/docs/index Retrieves the client's IP address and user agent information. ```APIDOC ## GET /ip ### Description Fetches the IP address and user agent of the client making the request. ### Method GET ### Endpoint /ip ### Parameters None ### Request Example ```javascript fetch('https://dummyjson.com/ip') .then(res => res.json()) .then(console.log); ``` ### Response #### Success Response (200) - **ip** (string) - The IP address of the client. - **userAgent** (string) - Information about the client's user agent. #### Response Example ```json { "ip": "127.0.0.1", "userAgent": "Mozilla/5.0 ..." } ``` ``` -------------------------------- ### Get Products by Category Source: https://dummyjson.com/docs/products Retrieves products belonging to a specific category. ```APIDOC ## GET /products/category/{categoryName} ### Description Retrieves a list of products that belong to a specified category. ### Method GET ### Endpoint `/products/category/{categoryName}` ### Path Parameters - **categoryName** (string) - Required - The name of the category to retrieve products for (e.g., 'smartphones'). ### Response #### Success Response (200) - **products** (array) - An array of product objects belonging to the specified category. - **total** (integer) - The total number of products in this category. - **skip** (integer) - The number of products skipped from the beginning. - **limit** (integer) - The maximum number of products to return. #### Response Example ```json { "products": [ { "id": 122, "title": "iPhone 6", "category": "smartphones", ... } // ... more products ], "total": 16, "skip": 0, "limit": 16 } ``` ``` -------------------------------- ### GET /image/{WIDTH}x{HEIGHT} Source: https://dummyjson.com/docs/image Generates a placeholder image with custom width and height. ```APIDOC ## GET /image/{WIDTH}x{HEIGHT} ### Description Generates a placeholder image with custom width and height. ### Method GET ### Endpoint `/image/WIDTHxHEIGHT` ### Parameters #### Path Parameters - **WIDTH** (integer) - Required - The width of the image in pixels. - **HEIGHT** (integer) - Required - The height of the image in pixels. ### Request Example ``` fetch('https://dummyjson.com/image/200x100') .then(response => response.blob()) .then(blob => { console.log('Fetched image blob:', blob); }) ``` ### Response #### Success Response (200) - **image blob** (blob) - The generated image file. #### Response Example ``` // Blob {size: SIZE, type: 'image/png'} ``` ``` -------------------------------- ### Get Products by Category (Smartphones) - JavaScript Source: https://dummyjson.com/docs/products Fetches all products belonging to the 'smartphones' category from the DummyJSON API. The response includes a list of smartphone products and pagination details. ```javascript fetch('https://dummyjson.com/products/category/smartphones') .then(res => res.json()) .then(console.log); ``` -------------------------------- ### GET /auth/me Source: https://dummyjson.com/docs/auth Retrieves the details of the currently authenticated user using the provided access token. ```APIDOC ## GET /auth/me ### Description Retrieves the details of the currently authenticated user. The access token should be provided in the Authorization header as a Bearer token. ### Method GET ### Endpoint /auth/me ### Parameters #### Path Parameters None #### Query Parameters None #### Headers - **Authorization** (string) - Required - The access token in the format `Bearer YOUR_ACCESS_TOKEN_HERE`. ### Request Example ```http GET /auth/me HTTP/1.1 Host: dummyjson.com Authorization: Bearer YOUR_ACCESS_TOKEN_HERE ``` ### Response #### Success Response (200) - **id** (number) - The user's ID. - **username** (string) - The user's username. - **email** (string) - The user's email address. - **firstName** (string) - The user's first name. - **lastName** (string) - The user's last name. - **gender** (string) - The user's gender. - **image** (string) - The URL of the user's image. - ... (other user fields) #### Response Example ```json { "id": 1, "username": "emilys", "email": "emily.johnson@x.dummyjson.com", "firstName": "Emily", "lastName": "Johnson", "gender": "female", "image": "https://dummyjson.com/icon/emilys/128" } ``` ``` -------------------------------- ### Get Single Todo Source: https://dummyjson.com/docs/todos Retrieves a specific to-do item by its unique ID. ```APIDOC ## GET /todos/{id} ### Description Retrieves a single to-do item based on its unique identifier. ### Method GET ### Endpoint /todos/{id} ### Path Parameters - **id** (integer) - Required - The unique identifier of the todo item. ### Request Example ``` fetch('https://dummyjson.com/todos/1') .then(res => res.json()) .then(console.log); ``` ### Response #### Success Response (200) - **id** (integer) - The unique identifier of the todo. - **todo** (string) - The description of the to-do task. - **completed** (boolean) - Indicates if the task is completed. - **userId** (integer) - The ID of the user associated with the todo. #### Response Example ```json { "id": 1, "todo": "Do something nice for someone I care about", "completed": true, "userId": 26 } ``` ``` -------------------------------- ### GET /users Source: https://dummyjson.com/docs/users Retrieves a list of users. Supports pagination with 'limit' and 'skip' query parameters. By default, it returns 30 users. ```APIDOC ## GET /users ### Description Retrieves a list of users. Supports pagination with 'limit' and 'skip' query parameters. By default, it returns 30 users. ### Method GET ### Endpoint /users ### Query Parameters - **limit** (integer) - Optional - The maximum number of users to return. - **skip** (integer) - Optional - The number of users to skip from the beginning of the list. ### Request Example ``` fetch('https://dummyjson.com/users?limit=10&skip=20') .then(res => res.json()) .then(console.log); ``` ### Response #### Success Response (200) - **users** (array) - An array of user objects. - **total** (integer) - The total number of users available. - **skip** (integer) - The number of users skipped. - **limit** (integer) - The limit of users returned. #### Response Example ```json { "users": [ { "id": 1, "firstName": "Emily", "lastName": "Johnson", "maidenName": "Smith", "age": 28, "gender": "female", "email": "emily.johnson@x.dummyjson.com", "phone": "+81 965-431-3024", "username": "emilys", "password": "emilyspass", "birthDate": "1996-5-30", "image": "...", "bloodGroup": "O-", "height": 193.24, "weight": 63.16, "eyeColor": "Green", "hair": { "color": "Brown", "type": "Curly" }, "ip": "42.48.100.32", "address": { "address": "626 Main Street", "city": "Phoenix", "state": "Mississippi", "stateCode": "MS", "postalCode": "29112", "coordinates": { "lat": -77.16213, "lng": -92.084824 }, "country": "United States" }, "macAddress": "47:fa:41:18:ec:eb", "university": "University of Wisconsin--Madison", "bank": { "cardExpire": "03/26", "cardNumber": "9289760655481815", "cardType": "Elo", "currency": "CNY", "iban": "YPUXISOBI7TTHPK2BR3HAIXL" }, "company": { "department": "Engineering", "name": "Dooley, Kozey and Cronin", "title": "Sales Manager", "address": { "address": "263 Tenth Street", "city": "San Francisco", "state": "Wisconsin", "stateCode": "WI", "postalCode": "37657", "coordinates": { "lat": 71.814525, "lng": -161.150263 }, "country": "United States" } }, "ein": "977-175", "ssn": "900-590-289", "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36", "crypto": { "coin": "Bitcoin", "wallet": "0xb9fc2fe63b2a6c003f1c324c3bfa53259162181a", "network": "Ethereum (ERC20)" }, "role": "admin" } // ... more user objects ], "total": 208, "skip": 0, "limit": 30 } ``` ``` -------------------------------- ### GET /posts/search?q={query} Source: https://dummyjson.com/docs/posts Searches for posts based on a query string. Returns a list of posts that match the search query. ```APIDOC ## GET /posts/search?q={query} ### Description Searches for posts based on a query string. Returns a list of posts that match the search query. ### Method GET ### Endpoint /posts/search ### Query Parameters - **q** (string) - Required - The search query string. ### Response #### Success Response (200) - **posts** (array) - An array of post objects matching the search query. - **total** (integer) - The total number of matching posts. - **skip** (integer) - The number of posts skipped. - **limit** (integer) - The number of posts returned. #### Response Example ```json { "posts": [ { "id": 7, "title": "This is important to remember.", "body": "This is important to remember. Love isn't like pie. You don't need to divide it among all your friends and loved ones. No matter how much love you give, you can always give more. It doesn't run out, so don't try to hold back giving it as if it may one day run out. Give it freely and as much as you want.", "tags": [ "magical", "crime" ], "reactions": { "likes": 127, "dislikes": 26 }, "views": 168, "userId": 70 } // ... more matching posts ], "total": 17, "skip": 0, "limit": 17 } ``` ``` -------------------------------- ### Get All Todos (JavaScript) Source: https://dummyjson.com/docs/todos Fetches all available to-do items from the API. By default, it returns 30 items. Use 'limit' and 'skip' parameters for pagination. ```javascript fetch('https://dummyjson.com/todos') .then(res => res.json()) .then(console.log); ``` -------------------------------- ### GET /icon/{HASH}/{SIZE} Source: https://dummyjson.com/docs/image Generates an identicon based on a hash. Supports PNG and SVG formats. ```APIDOC ## GET /icon/{HASH}/{SIZE} ### Description Generates an identicon based on a hash. Supports PNG and SVG formats. ### Method GET ### Endpoint `/icon/HASH/SIZE` ### Parameters #### Path Parameters - **HASH** (string) - Required - The hash string to generate the identicon from. - **SIZE** (integer) - Optional - The size of the identicon in pixels. Defaults to a standard size. #### Query Parameters - **type** (string) - Optional - The desired format (`png` or `svg`). Defaults to `png`. ### Request Example ``` fetch('https://dummyjson.com/icon/abc123/150') // png is default .then(response => response.blob()) .then(blob => { console.log('Fetched image blob:', blob); }) ``` ### Response #### Success Response (200) - **image blob** (blob) - The generated identicon file. #### Response Example ``` // Blob {size: SIZE, type: 'image/png'} ``` ``` -------------------------------- ### GET /image/{SIZE} Source: https://dummyjson.com/docs/image Generates a square placeholder image of a specified size. The size is provided in pixels. ```APIDOC ## GET /image/{SIZE} ### Description Generates a square placeholder image of a specified size. ### Method GET ### Endpoint `/image/SIZE` ### Parameters #### Path Parameters - **SIZE** (integer) - Required - The size of the square image in pixels (e.g., 150). ### Request Example ``` fetch('https://dummyjson.com/image/150') .then(response => response.blob()) .then(blob => { console.log('Fetched image blob:', blob); }) ``` ### Response #### Success Response (200) - **image blob** (blob) - The generated image file. #### Response Example ``` // Blob {size: SIZE, type: 'image/png'} ``` ``` -------------------------------- ### Get All Product Categories - JavaScript Source: https://dummyjson.com/docs/products Retrieves a list of all available product categories from the DummyJSON API. The response is an array of category objects, each containing a slug, name, and URL. ```javascript fetch('https://dummyjson.com/products/categories') .then(res => res.json()) .then(console.log); ``` -------------------------------- ### GET /image/?text={TEXT}&fontSize={FONT_SIZE} Source: https://dummyjson.com/docs/image Generates an image with custom text and a specified font size. ```APIDOC ## GET /image/?text={TEXT}&fontSize={FONT_SIZE} ### Description Generates an image with custom text and a specified font size. ### Method GET ### Endpoint `/image/SIZE/?text=TEXT&fontSize=FONT_SIZE` ### Parameters #### Query Parameters - **text** (string) - Required - The text to display on the image. - **fontSize** (integer) - Required - The size of the font. - **SIZE** (integer) - Optional - The size of the square image in pixels. - **BACKGROUND_COLOR** (string) - Optional - The background color in hexadecimal format. - **TEXT_COLOR** (string) - Optional - The text color in hexadecimal format. ### Request Example ``` fetch('https://dummyjson.com/image/400x200/008080/ffffff?text=Hello+Peter!&fontSize=16') .then(response => response.blob()) .then(blob => { console.log('Fetched image blob:', blob); }) ``` ### Response #### Success Response (200) - **image blob** (blob) - The generated image file. #### Response Example ``` // Blob {size: SIZE, type: 'image/png'} ``` ``` -------------------------------- ### Get All Recipes Source: https://dummyjson.com/docs/recipes Retrieves a list of recipes. By default, it returns 30 items. Use 'limit' and 'skip' parameters for pagination. 'limit=0' fetches all items. ```APIDOC ## GET /recipes ### Description Retrieves a list of recipes. Supports pagination and selecting specific fields. ### Method GET ### Endpoint /recipes ### Query Parameters - **limit** (integer) - Optional - The maximum number of recipes to return. Default is 30. Use 0 to get all. - **skip** (integer) - Optional - The number of recipes to skip from the beginning. Default is 0. - **select** (string) - Optional - Comma-separated list of fields to include in the response. - **sortBy** (string) - Optional - The field name to sort the results by. - **order** (string) - Optional - The order of sorting ('asc' or 'desc'). ### Request Example ```javascript fetch('https://dummyjson.com/recipes?limit=10&skip=10&select=name,image') .then(res => res.json()) .then(console.log); ``` ### Response #### Success Response (200) - **recipes** (array) - An array of recipe objects. - **total** (integer) - The total number of recipes available. - **skip** (integer) - The number of recipes skipped. - **limit** (integer) - The number of recipes returned. #### Response Example ```json { "recipes": [ { "id": 11, "name": "Chicken Biryani", "image": "https://cdn.dummyjson.com/recipe-images/11.webp" } ], "total": 50, "skip": 10, "limit": 10 } ``` ``` -------------------------------- ### Get Product Category List - JavaScript Source: https://dummyjson.com/docs/products Fetches a simple list of product category names from the DummyJSON API. The response is a flat array of strings, where each string is a category name. ```javascript fetch('https://dummyjson.com/products/category-list') .then(res => res.json()) .then(console.log); ``` -------------------------------- ### Get All Post Tags - JavaScript Source: https://dummyjson.com/docs/posts Retrieves a list of all available tags for posts. Each tag includes its slug, name, and a URL to fetch posts by that tag. ```javascript fetch('https://dummyjson.com/posts/tags') .then(res => res.json()) .then(console.log); ``` -------------------------------- ### GET /user/me Source: https://dummyjson.com/docs/users Retrieves the profile of the currently authenticated user. Authentication can be done via the Authorization header (Bearer token) or by including cookies. ```APIDOC ## GET /user/me ### Description Retrieves the profile of the currently authenticated user. Authentication can be done via the Authorization header (Bearer token) or by including cookies. ### Method GET ### Endpoint /user/me ### Parameters #### Headers - **Authorization** (string) - Optional - The JWT access token in the format 'Bearer YOUR_ACCESS_TOKEN_HERE'. ### Request Example ```javascript // Providing access token in bearer header fetch('https://dummyjson.com/user/me', { method: 'GET', headers: { 'Authorization': 'Bearer /* YOUR_ACCESS_TOKEN_HERE */' }, credentials: 'include' // Include cookies (e.g., accessToken) in the request }) .then(res => res.json()) .then(console.log); ``` ### Response #### Success Response (200) - **id** (integer) - The user's ID. - **firstName** (string) - The user's first name. - **lastName** (string) - The user's last name. - **maidenName** (string) - The user's maiden name. - **age** (integer) - The user's age. - **gender** (string) - The user's gender. - **email** (string) - The user's email. - **image** (string) - The URL to the user's image. - /* ... rest of user data */ #### Response Example ```json { "id": 1, "firstName": "Emily", "lastName": "Johnson", "maidenName": "Smith", "age": 28, "gender": "female", "email": "emily.johnson@x.dummyjson.com", "image": "..." // ... rest of user data } ``` ``` -------------------------------- ### Fetch All Recipe Tags (JavaScript) Source: https://dummyjson.com/docs/recipes Retrieves a list of all available tags for recipes from the DummyJSON API. This is useful for filtering or categorizing recipes. It makes a GET request to the '/recipes/tags' endpoint. ```javascript fetch('https://dummyjson.com/recipes/tags') .then(res => res.json()) .then(console.log); ``` -------------------------------- ### Fetch Recipes by Tag (JavaScript) Source: https://dummyjson.com/docs/recipes Fetches recipes associated with a specific tag. For example, to get all 'Pakistani' recipes. This uses a GET request to '/recipes/tag/{tag}'. ```javascript fetch('https://dummyjson.com/recipes/tag/Pakistani') .then(res => res.json()) .then(console.log); ``` -------------------------------- ### Search Products by Query (JavaScript) Source: https://dummyjson.com/docs/products Searches for products based on a query string. The 'q' parameter is used to specify the search term. This example demonstrates how to fetch search results using the fetch API and log the response. ```javascript fetch('https://dummyjson.com/products/search?q=phone') .then(res => res.json()) .then(console.log); ``` -------------------------------- ### Add New Product - JavaScript Source: https://dummyjson.com/docs/products Simulates adding a new product to the DummyJSON API using a POST request. It requires a JSON payload with product details. The API returns the newly created product with a unique ID. ```javascript fetch('https://dummyjson.com/products/add', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ title: 'BMW Pencil', /* other product data */ }) }) .then(res => res.json()) .then(console.log); ``` -------------------------------- ### Get Client IP Address with DummyJSON Source: https://dummyjson.com/docs/index Retrieve the client's IP address and user agent information by making a GET request to the /ip endpoint of the DummyJSON API. This is useful for logging or geolocation purposes. ```javascript // GET fetch('https://dummyjson.com/ip') .then(res => res.json()) .then(console.log); /* { ip: '127.0.0.1', userAgent: 'Mozilla/5.0 ...' } */ ``` -------------------------------- ### Authorizing Resources Source: https://dummyjson.com/docs/index Access resources as an authorized user by including an access token in the 'Authorization' header. Generate tokens via the auth module. ```APIDOC ## [HTTP_METHOD] /auth/RESOURCE ### Description Accesses resources as an authorized user using a bearer token. ### Method GET, POST, PUT, PATCH, DELETE ### Endpoint /auth/RESOURCE ### Parameters #### Request Headers - **Authorization** (string) - Required - Bearer token for authentication. Format: `Bearer YOUR_ACCESS_TOKEN_HERE`. - **Content-Type** (string) - Required - `application/json`. ### Request Example ```javascript fetch('https://dummyjson.com/auth/RESOURCE', { method: 'GET', // or POST/PUT/PATCH/DELETE headers: { 'Authorization': 'Bearer YOUR_ACCESS_TOKEN_HERE', 'Content-Type': 'application/json' }, }) .then(res => res.json()) .then(console.log); ``` ### Response #### Success Response (200) - **(authorized resource data)** (any) - The data of the requested resource for an authorized user. #### Response Example ```json { "data": "authorized_resource_content" } ``` ``` -------------------------------- ### Get User Todos by User ID (JavaScript) Source: https://dummyjson.com/docs/users Fetches all todos associated with a specific user ID from the DummyJSON API. It uses the fetch API to make a GET request and processes the JSON response. ```javascript /* getting todos of user with id 5 */ fetch('https://dummyjson.com/users/5/todos') .then(res => res.json()) .then(console.log); ``` -------------------------------- ### Get Single User by ID - JavaScript Source: https://dummyjson.com/docs/users Retrieves the data for a specific user identified by their unique ID. This function uses the fetch API to make a GET request to the users endpoint with the user's ID as a path parameter. ```javascript fetch('https://dummyjson.com/users/1') .then(res => res.json()) .then(console.log); ``` -------------------------------- ### Add a New Product Source: https://dummyjson.com/docs/products Simulates adding a new product. The product is not actually added to the server but returned with a new ID. ```APIDOC ## POST /products/add ### Description Simulates the creation of a new product. This endpoint does not persist the data on the server but returns the newly created product object with a generated ID. ### Method POST ### Endpoint `/products/add` ### Request Body - **title** (string) - Required - The title of the new product. - ***other product data*** (any) - Optional - Other fields for the product (e.g., description, price, brand, etc.). ### Request Example ```javascript fetch('https://dummyjson.com/products/add', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ title: 'BMW Pencil', /* other product data */ }) }) .then(res => res.json()) .then(console.log); ``` ### Response #### Success Response (200) - **id** (integer) - The newly generated ID for the simulated product. - **title** (string) - The title of the added product. - ***other product data*** (any) - Other fields included in the request. #### Response Example ```json { "id": 195, "title": "BMW Pencil", /* other product data */ } ``` ``` -------------------------------- ### Limit and Select DummyJSON Resources Source: https://dummyjson.com/docs/index Learn to paginate and select specific fields from DummyJSON resources using query parameters. 'limit' controls the number of items, 'skip' offsets the results, and 'select' specifies the keys to include. ```javascript fetch('https://dummyjson.com/RESOURCE/?limit=10&skip=5&select=key1,key2,key3'); ``` ```javascript fetch('https://dummyjson.com/RESOURCE/?limit=10&skip=5&select=key1&select=key2&select=key3'); ``` -------------------------------- ### Get Single Recipe Source: https://dummyjson.com/docs/recipes Retrieves a single recipe by its ID. ```APIDOC ## GET /recipes/{id} ### Description Retrieves a single recipe by its unique identifier. ### Method GET ### Endpoint /recipes/{id} ### Path Parameters - **id** (integer) - Required - The unique identifier of the recipe. ### Request Example ```javascript fetch('https://dummyjson.com/recipes/1') .then(res => res.json()) .then(console.log); ``` ### Response #### Success Response (200) - **id** (integer) - The unique identifier of the recipe. - **name** (string) - The name of the recipe. - **ingredients** (array) - A list of ingredients. - **instructions** (array) - A list of cooking instructions. - **prepTimeMinutes** (integer) - Preparation time in minutes. - **cookTimeMinutes** (integer) - Cooking time in minutes. - **servings** (integer) - Number of servings. - **difficulty** (string) - Difficulty level (e.g., Easy, Medium, Hard). - **cuisine** (string) - Type of cuisine (e.g., Italian, Indian). - **caloriesPerServing** (integer) - Calories per serving. - **tags** (array) - Tags associated with the recipe. - **userId** (integer) - The ID of the user who added the recipe. - **image** (string) - URL of the recipe image. - **rating** (float) - Average rating of the recipe. - **reviewCount** (integer) - Number of reviews. - **mealType** (array) - Type of meal (e.g., Dinner, Breakfast). #### Response Example ```json { "id": 1, "name": "Classic Margherita Pizza", "ingredients": [ "Pizza dough", "Tomato sauce", "Fresh mozzarella cheese", "Fresh basil leaves", "Olive oil", "Salt and pepper to taste" ], "instructions": [ "Preheat the oven to 475°F (245°C).", "Roll out the pizza dough and spread tomato sauce evenly.", "Top with slices of fresh mozzarella and fresh basil leaves.", "Drizzle with olive oil and season with salt and pepper.", "Bake in the preheated oven for 12-15 minutes or until the crust is golden brown.", "Slice and serve hot." ], "prepTimeMinutes": 20, "cookTimeMinutes": 15, "servings": 4, "difficulty": "Easy", "cuisine": "Italian", "caloriesPerServing": 300, "tags": [ "Pizza", "Italian" ], "userId": 45, "image": "https://cdn.dummyjson.com/recipe-images/1.webp", "rating": 4.6, "reviewCount": 3, "mealType": [ "Dinner" ] } ``` ``` -------------------------------- ### GET /posts/tag-list Source: https://dummyjson.com/docs/posts Retrieves a list of all unique post tags. ```APIDOC ## GET /posts/tag-list ### Description Retrieves a list of all unique post tags. ### Method GET ### Endpoint /posts/tag-list ### Response #### Success Response (200) - **tag_list** (array) - An array of unique tag strings. #### Response Example ```json [ "history", "american", "crime", "french", "fiction", "english" // ... more tags ] ``` ``` -------------------------------- ### Fetch All Posts - JavaScript Source: https://dummyjson.com/docs/posts Retrieves all posts from the API. By default, it returns 30 items. The 'limit' and 'skip' parameters can be used for pagination. ```javascript fetch('https://dummyjson.com/posts') .then(res => res.json()) .then(console.log); ``` -------------------------------- ### Get Single Comment Source: https://dummyjson.com/docs/comments Retrieves a specific comment by its ID. ```APIDOC ## GET /comments/{id} ### Description Retrieves a single comment by its unique identifier. ### Method GET ### Endpoint /comments/{id} ### Path Parameters - **id** (integer) - Required - The ID of the comment to retrieve. ### Response #### Success Response (200) - **id** (integer) - The comment's unique identifier. - **body** (string) - The content of the comment. - **postId** (integer) - The ID of the post the comment belongs to. - **likes** (integer) - The number of likes the comment has received. - **user** (object) - Information about the user who posted the comment. - **id** (integer) - The user's unique identifier. - **username** (string) - The user's username. - **fullName** (string) - The user's full name. #### Response Example ```json { "id": 1, "body": "This is some awesome thinking!", "postId": 242, "likes": 3, "user": { "id": 105, "username": "emmac", "fullName": "Emma Wilson" } } ``` ``` -------------------------------- ### Get All Todos Source: https://dummyjson.com/docs/todos Retrieves a list of all to-do items. By default, it returns 30 items. Pagination can be controlled using the 'limit' and 'skip' query parameters. Setting 'limit=0' retrieves all items. ```APIDOC ## GET /todos ### Description Retrieves a list of all to-do items. Supports pagination via 'limit' and 'skip' query parameters. ### Method GET ### Endpoint /todos ### Query Parameters - **limit** (integer) - Optional - The maximum number of todos to return. Default is 30. Use 0 to get all items. - **skip** (integer) - Optional - The number of todos to skip from the beginning. ### Request Example ``` fetch('https://dummyjson.com/todos?limit=10&skip=5') .then(res => res.json()) .then(console.log); ``` ### Response #### Success Response (200) - **todos** (array) - An array of todo objects. - **total** (integer) - The total number of available todos. - **skip** (integer) - The number of todos skipped. - **limit** (integer) - The limit of todos returned. #### Response Example ```json { "todos": [ { "id": 6, "todo": "Plan a vacation", "completed": false, "userId": 1 } // ... more todos ], "total": 150, "skip": 5, "limit": 10 } ``` ``` -------------------------------- ### GET /posts/{id} Source: https://dummyjson.com/docs/posts Retrieves a single post by its unique ID. ```APIDOC ## GET /posts/{id} ### Description Retrieves a single post by its unique ID. ### Method GET ### Endpoint /posts/{id} ### Path Parameters - **id** (integer) - Required - The unique identifier of the post. ### Response #### Success Response (200) - **id** (integer) - The unique identifier of the post. - **title** (string) - The title of the post. - **body** (string) - The content of the post. - **tags** (array) - An array of tags associated with the post. - **reactions** (object) - An object containing like and dislike counts. - **views** (integer) - The number of views the post has. - **userId** (integer) - The ID of the user who created the post. #### Response Example ```json { "id": 1, "title": "His mother had always taught him", "body": "His mother had always taught him not to ever think of himself as better than others. He'd tried to live by this motto. He never looked down on those who were less fortunate or who had less money than him. But the stupidity of the group of people he was talking to made him change his mind.", "tags": [ "history", "american", "crime" ], "reactions": { "likes": 192, "dislikes": 25 }, "views": 305, "userId": 121 } ``` ```