### Response sample for GET /products/{id} Source: https://fakestoreapi.com/docs Example JSON response for a successful (200) request, showing the product fields: id, title, price, description, category, and image. ```JSON { "id": 0, "title": "string", "price": 0.1, "description": "string", "category": "string", "image": "http://example.com" } ``` -------------------------------- ### GET /products Source: https://fakestoreapi.com/docs-data Retrieves all products from the FakeStoreAPI. ```APIDOC ## GET /products ### Description Retrieve a list of all available products. ### Method GET ### Endpoint https://fakestoreapi.com/products ### Parameters None ### Request Example None ### Response #### Success Response (200) - **array of Product** - List of products #### Response Example ```json [ { "id": 1, "title": "...", "price": 109.95, "description": "...", "category": "...", "image": "...", "rating": { "rate": 3.9, "count": 120 } } ] ``` ### Error Handling - **400** - Bad request ``` -------------------------------- ### Get all products (cURL) Source: https://fakestoreapi.com/docs-data Retrieve a list of all available products using a cURL GET request. ```curl curl -X GET 'https://fakestoreapi.com/products' ``` -------------------------------- ### Get all products (PHP) Source: https://fakestoreapi.com/docs-data Retrieve a list of all available products using PHP's file_get_contents. ```php ``` -------------------------------- ### Get all products (Python) Source: https://fakestoreapi.com/docs-data Retrieve a list of all available products using the Python requests library. ```python import requests response = requests.get('https://fakestoreapi.com/products') print(response.json()) ``` -------------------------------- ### Get all products (Node.js) Source: https://fakestoreapi.com/docs-data Retrieve a list of all available products using the Axios library in Node.js. ```nodejs const axios = require('axios'); axios.get('https://fakestoreapi.com/products') .then(response => console.log(response.data)); ``` -------------------------------- ### Get all products (JavaScript) Source: https://fakestoreapi.com/docs-data Retrieve a list of all available products using the browser's fetch API. ```javascript fetch('https://fakestoreapi.com/products') .then(response => response.json()) .then(data => console.log(data)); ``` -------------------------------- ### Get a single product (cURL) Source: https://fakestoreapi.com/docs-data Retrieve details of a specific product by ID using a cURL GET request. ```curl curl -X GET 'https://fakestoreapi.com/products/1' ``` -------------------------------- ### GET /products/{id} Source: https://fakestoreapi.com/docs-data Retrieves a single product by its ID. ```APIDOC ## GET /products/{id} ### Description Retrieve details of a specific product by ID. ### Method GET ### Endpoint https://fakestoreapi.com/products/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - Product ID ### Request Example None ### Response #### Success Response (200) - **Product** - The product details #### Response Example ```json { "id": 1, "title": "...", "price": 109.95, "description": "...", "category": "...", "image": "...", "rating": { "rate": 3.9, "count": 120 } } ``` ### Error Handling - **400** - Bad request ``` -------------------------------- ### Get all users with fetch Source: https://fakestoreapi.com/docs Retrieves a list of all users from the API. ```javascript fetch('https://fakestoreapi.com/users') .then(response => response.json()) .then(data => console.log(data)); ``` -------------------------------- ### GET /users Source: https://fakestoreapi.com/docs-data Retrieves a list of all users. ```APIDOC ## GET /users ### Description Retrieve a list of all users. ### Method GET ### Endpoint https://fakestoreapi.com/users ### Response #### Success Response (200) - Returns an array of User objects. #### Error Response (400) - Bad request ``` -------------------------------- ### Get all carts with GET - JavaScript, Node.js, PHP, cURL, Python Source: https://fakestoreapi.com/docs-data Retrieve a list of all available carts using the GET method. The response is an array of cart objects. No parameters are required. ```javascript fetch('https://fakestoreapi.com/carts') .then(response => response.json()) .then(data => console.log(data)); ``` ```nodejs const axios = require('axios'); axios.get('https://fakestoreapi.com/carts') .then(response => console.log(response.data)); ``` ```php ``` ```curl curl -X GET 'https://fakestoreapi.com/carts' ``` ```python import requests response = requests.get('https://fakestoreapi.com/carts') print(response.json()) ``` -------------------------------- ### Get a single product (PHP) Source: https://fakestoreapi.com/docs-data Retrieve details of a specific product by ID using PHP's file_get_contents. ```php ``` -------------------------------- ### Get a single cart via cURL Source: https://fakestoreapi.com/docs-data Retrieves cart details using a GET request. ```curl curl -X GET 'https://fakestoreapi.com/carts/1' ``` -------------------------------- ### Get a single product (Python) Source: https://fakestoreapi.com/docs-data Retrieve details of a specific product by ID using the Python requests library. ```python import requests response = requests.get('https://fakestoreapi.com/products/1') print(response.json()) ``` -------------------------------- ### Get a single cart via PHP Source: https://fakestoreapi.com/docs-data Retrieves cart details using file_get_contents. ```php ``` -------------------------------- ### Get a single cart via Python Source: https://fakestoreapi.com/docs-data Retrieves cart details using the requests library. ```python import requests response = requests.get('https://fakestoreapi.com/carts/1') print(response.json()) ``` -------------------------------- ### Get a single product (Node.js) Source: https://fakestoreapi.com/docs-data Retrieve details of a specific product by ID using the Axios library in Node.js. ```nodejs const axios = require('axios'); axios.get('https://fakestoreapi.com/products/1') .then(response => console.log(response.data)); ``` -------------------------------- ### Get all carts using fetch Source: https://fakestoreapi.com/docs Retrieves a list of all available carts from the API. ```javascript fetch('https://fakestoreapi.com/carts') .then(response => response.json()) .then(data => console.log(data)); ``` -------------------------------- ### Get a single cart via Node.js Source: https://fakestoreapi.com/docs-data Retrieves cart details using the Axios library. ```nodejs const axios = require('axios'); axios.get('https://fakestoreapi.com/carts/1') .then(response => console.log(response.data)); ``` -------------------------------- ### Get all users response schema Source: https://fakestoreapi.com/docs The JSON structure returned when successfully retrieving all users. ```json [ { "id": 0, "username": "string", "email": "string", "password": "string" } ] ``` -------------------------------- ### Get all users with JavaScript, Node.js, PHP, cURL, and Python Source: https://fakestoreapi.com/docs-data Retrieve a list of all users from the Fake Store API. The endpoint returns an array of user objects. Use this snippet to fetch all users in your application. ```javascript fetch('https://fakestoreapi.com/users') .then(response => response.json()) .then(data => console.log(data)); ``` ```nodejs const axios = require('axios'); axios.get('https://fakestoreapi.com/users') .then(response => console.log(response.data)); ``` ```php ``` ```curl curl -X GET 'https://fakestoreapi.com/users' ``` ```python import requests response = requests.get('https://fakestoreapi.com/users') print(response.json()) ``` -------------------------------- ### Get a single product (JavaScript) Source: https://fakestoreapi.com/docs-data Retrieve details of a specific product by ID using the browser's fetch API. ```javascript fetch('https://fakestoreapi.com/products/1') .then(response => response.json()) .then(data => console.log(data)); ``` -------------------------------- ### GET /users/{id} Source: https://fakestoreapi.com/docs-data Retrieves details of a specific user by their ID. ```APIDOC ## GET /users/{id} ### Description Retrieve details of a specific user by ID. ### Method GET ### Endpoint https://fakestoreapi.com/users/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the user to retrieve. ### Response #### Success Response (200) - Returns the User object. #### Error Response (400) - Bad request ``` -------------------------------- ### GET /carts/{id} Source: https://fakestoreapi.com/docs-data Retrieves details of a specific cart by ID. ```APIDOC ## GET /carts/{id} ### Description Retrieves details of a specific cart by ID. ### Method GET ### Endpoint https://fakestoreapi.com/carts/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the cart to retrieve. ### Response #### Success Response (200) - **id** (integer) - The ID of the cart. - **userId** (integer) - The ID of the user who owns the cart. - **date** (string) - The date the cart was created. - **products** (array) - An array of product objects, each containing **productId** (integer) and **quantity** (integer). #### Response Example { "id": 1, "userId": 1, "date": "2020-02-03T12:00:00.000Z", "products": [ { "productId": 1, "quantity": 1 } ] } #### Error Response (400) Bad request - invalid ID. ``` -------------------------------- ### Get all carts response schema Source: https://fakestoreapi.com/docs The JSON structure returned when successfully retrieving all carts. ```json [ { "id": 0, "userId": 0, "products": [ { "id": 0, "title": "string", "price": 0.1, "description": "string", "category": "string", "image": "http://example.com" } ] } ] ``` -------------------------------- ### Get a single user by ID with JavaScript, Node.js, PHP, cURL, and Python Source: https://fakestoreapi.com/docs-data Retrieve details of a specific user by ID. The path parameter 'id' is required and must be an integer. A successful request returns a 200 status with the user object. ```javascript fetch('https://fakestoreapi.com/users/1') .then(response => response.json()) .then(data => console.log(data)); ``` ```nodejs const axios = require('axios'); axios.get('https://fakestoreapi.com/users/1') .then(response => console.log(response.data)); ``` ```php ``` ```curl curl -X GET 'https://fakestoreapi.com/users/1' ``` ```python import requests response = requests.get('https://fakestoreapi.com/users/1') print(response.json()) ``` -------------------------------- ### Get a single cart via JavaScript Source: https://fakestoreapi.com/docs-data Retrieves cart details using the browser's fetch API. ```javascript fetch('https://fakestoreapi.com/carts/1') .then(response => response.json()) .then(data => console.log(data)); ``` -------------------------------- ### GET /carts Source: https://fakestoreapi.com/docs Retrieves a list of all available carts. Returns an array of cart objects with product details. ```APIDOC ## GET /carts ### Description Retrieve a list of all available carts. ### Method GET ### Endpoint https://fakestoreapi.com/carts ### Responses #### Success Response (200) Success #### Error Response (400) Bad request ### Request Example ``` fetch('https://fakestoreapi.com/carts') .then(response => response.json()) .then(data => console.log(data)); ``` ### Response Example ```json [ { "id": 0, "userId": 0, "products": [ { "id": 0, "title": "string", "price": 0.1, "description": "string", "category": "string", "image": "http://example.com" } ] } ] ``` ``` -------------------------------- ### Get a single user with fetch Source: https://fakestoreapi.com/docs Retrieve details of a specific user by ID using the browser's fetch API. ```javascript fetch('https://fakestoreapi.com/users/1') .then(response => response.json()) .then(data => console.log(data)); ``` -------------------------------- ### POST /products Source: https://fakestoreapi.com/docs-data Creates a new product in the FakeStoreAPI. ```APIDOC ## POST /products ### Description Create a new product. ### Method POST ### Endpoint https://fakestoreapi.com/products ### Parameters #### Request Body - **title** (string) - Required - Product title - **price** (number) - Required - Product price ### Request Example ```json { "title": "New Product", "price": 29.99 } ``` ### Response #### Success Response (201) - **Product** - The created product #### Response Example ```json { "id": 21, "title": "New Product", "price": 29.99 } ``` ### Error Handling - **400** - Bad request ``` -------------------------------- ### Add a new product (Python) Source: https://fakestoreapi.com/docs-data Create a new product using the Python requests library with a POST request. ```python import requests product = {'title': 'New Product', 'price': 29.99} response = requests.post('https://fakestoreapi.com/products', json=product) print(response.json()) ``` -------------------------------- ### Add a new product (Node.js) Source: https://fakestoreapi.com/docs-data Create a new product using the Axios library in Node.js with a POST request. ```nodejs const axios = require('axios'); const product = { title: 'New Product', price: 29.99 }; axios.post('https://fakestoreapi.com/products', product) .then(response => console.log(response.data)); ``` -------------------------------- ### Add a new product (JavaScript) Source: https://fakestoreapi.com/docs-data Create a new product using the browser's fetch API with a POST request. ```javascript const product = { title: 'New Product', price: 29.99 }; fetch('https://fakestoreapi.com/products', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(product) }) .then(response => response.json()) .then(data => console.log(data)); ``` -------------------------------- ### POST /users Source: https://fakestoreapi.com/docs-data Creates a new user with the provided details. ```APIDOC ## POST /users ### Description Create a new user. ### Method POST ### Endpoint https://fakestoreapi.com/users ### Parameters #### Request Body - **username** (string) - Required - The username for the new user. - **email** (string) - Required - The email address for the new user. - **password** (string) - Required - The password for the new user. ### Response #### Success Response (201) - Returns the created User object. #### Error Response (400) - Bad request ``` -------------------------------- ### Add a new user with JavaScript, Node.js, PHP, cURL, and Python Source: https://fakestoreapi.com/docs-data Create a new user by sending a POST request to the /users endpoint. The request body must include username, email, and password. A successful creation returns a 201 status with the created user object. ```javascript const user = { username: 'john_doe', email: 'john@example.com', password: 'pass123' }; fetch('https://fakestoreapi.com/users', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(user) }) .then(response => response.json()) .then(data => console.log(data)); ``` ```nodejs const axios = require('axios'); const user = { username: 'john_doe', email: 'john@example.com', password: 'pass123' }; axios.post('https://fakestoreapi.com/users', user) .then(response => console.log(response.data)); ``` ```php 'john_doe', 'email' => 'john@example.com', 'password' => 'pass123']); $ch = curl_init('https://fakestoreapi.com/users'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $user); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); $response = curl_exec($ch); curl_close($ch); echo $response; ?> ``` ```curl curl -X POST 'https://fakestoreapi.com/users' -H 'Content-Type: application/json' -d '{"username": "john_doe", "email": "john@example.com", "password": "pass123"}' ``` ```python import requests user = {'username': 'john_doe', 'email': 'john@example.com', 'password': 'pass123'} response = requests.post('https://fakestoreapi.com/users', json=user) print(response.json()) ``` -------------------------------- ### Add a new product (PHP) Source: https://fakestoreapi.com/docs-data Create a new product using PHP's cURL library. ```php 'New Product', 'price' => 29.99]); $ch = curl_init('https://fakestoreapi.com/products'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $product); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); $response = curl_exec($ch); curl_close($ch); echo $response; ?> ``` -------------------------------- ### Login with POST /auth/login Source: https://fakestoreapi.com/docs-data Authenticate a user by sending credentials to the /auth/login endpoint. The request body must include username and password. A successful login returns a 200 response; a bad request returns 400. ```javascript const credentials = { username: 'john_doe', password: 'pass123' }; fetch('https://fakestoreapi.com/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(credentials) }) .then(response => response.json()) .then(data => console.log(data)); ``` ```nodejs const axios = require('axios'); const credentials = { username: 'john_doe', password: 'pass123' }; axios.post('https://fakestoreapi.com/auth/login', credentials) .then(response => console.log(response.data)); ``` ```php 'john_doe', 'password' => 'pass123']); $ch = curl_init('https://fakestoreapi.com/auth/login'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $credentials); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); $response = curl_exec($ch); curl_close($ch); echo $response; ?> ``` ```curl curl -X POST 'https://fakestoreapi.com/auth/login' -H 'Content-Type: application/json' -d '{"username": "john_doe", "password": "pass123"}' ``` ```python import requests credentials = {'username': 'john_doe', 'password': 'pass123'} response = requests.post('https://fakestoreapi.com/auth/login', json=credentials) print(response.json()) ``` -------------------------------- ### Add a new product (cURL) Source: https://fakestoreapi.com/docs-data Create a new product using a cURL POST request with JSON data. ```curl curl -X POST 'https://fakestoreapi.com/products' -H 'Content-Type: application/json' -d '{"title": "New Product", "price": 29.99}' ``` -------------------------------- ### POST /auth/login Source: https://fakestoreapi.com/docs-data Authenticates a user with username and password, returning an authentication token upon success. ```APIDOC ## POST /auth/login ### Description Authenticate a user. ### Method POST ### Endpoint https://fakestoreapi.com/auth/login ### Parameters #### Request Body - **username** (string) - Required - The user's username. - **password** (string) - Required - The user's password. ### Request Example { "username": "john_doe", "password": "pass123" } ### Response #### Success Response (200) - **token** (string) - Authentication token. #### Response Example { "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." } #### Error Response (400) - **message** (string) - Error description. ### Code Samples #### JavaScript (Browser) ```javascript const credentials = { username: 'john_doe', password: 'pass123' }; fetch('https://fakestoreapi.com/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(credentials) }) .then(response => response.json()) .then(data => console.log(data)); ``` #### Node.js (Axios) ```javascript const axios = require('axios'); const credentials = { username: 'john_doe', password: 'pass123' }; axios.post('https://fakestoreapi.com/auth/login', credentials) .then(response => console.log(response.data)); ``` #### PHP ```php 'john_doe', 'password' => 'pass123']); $ch = curl_init('https://fakestoreapi.com/auth/login'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $credentials); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); $response = curl_exec($ch); curl_close($ch); echo $response; ?> ``` #### cURL ```bash curl -X POST 'https://fakestoreapi.com/auth/login' -H 'Content-Type: application/json' -d '{"username": "john_doe", "password": "pass123"}' ``` #### Python ```python import requests credentials = {'username': 'john_doe', 'password': 'pass123'} response = requests.post('https://fakestoreapi.com/auth/login', json=credentials) print(response.json()) ``` ``` -------------------------------- ### POST /carts Source: https://fakestoreapi.com/docs-data Creates a new cart for a user with a list of products. ```APIDOC ## POST /carts ### Description Creates a new cart for a user with a list of products. ### Method POST ### Endpoint https://fakestoreapi.com/carts ### Parameters #### Request Body - **userId** (integer) - Required - The ID of the user who owns the cart. - **products** (array) - Required - An array of product objects, each containing an **id** (integer) of the product. ### Request Example { "userId": 1, "products": [ { "id": 1 } ] } ### Response #### Success Response (201) - **id** (integer) - The ID of the newly created cart. - **userId** (integer) - The ID of the user who owns the cart. - **date** (string) - The date the cart was created. - **products** (array) - An array of product objects, each containing **productId** (integer) and **quantity** (integer). #### Response Example { "id": 5, "userId": 1, "date": "2020-02-03T12:00:00.000Z", "products": [ { "productId": 1, "quantity": 1 } ] } #### Error Response (400) Bad request - invalid input data. ``` -------------------------------- ### PUT /products/{id} Source: https://fakestoreapi.com/docs-data Updates an existing product by its ID. ```APIDOC ## PUT /products/{id} ### Description Update an existing product by ID. ### Method PUT ### Endpoint https://fakestoreapi.com/products/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - Product ID #### Request Body - **title** (string) - Required - Updated product title - **price** (number) - Required - Updated product price ### Request Example ```json { "title": "Updated Product", "price": 39.99 } ``` ### Response #### Success Response (200) - **Product** - The updated product #### Response Example ```json { "id": 1, "title": "Updated Product", "price": 39.99 } ``` ### Error Handling - **400** - Bad request ``` -------------------------------- ### Create a new cart via Python Source: https://fakestoreapi.com/docs-data Uses the requests library to post a new cart object to the API. ```python import requests cart = {'userId': 1, 'products': [{'id': 1}]} response = requests.post('https://fakestoreapi.com/carts', json=cart) print(response.json()) ``` -------------------------------- ### Add new cart with POST - JavaScript, Node.js, PHP Source: https://fakestoreapi.com/docs-data Create a new cart by sending a POST request with a cart object containing userId and products array. The request body is required and must be in JSON format. The response returns the created cart. ```javascript const cart = { userId: 1, products: [{ id: 1 }] }; fetch('https://fakestoreapi.com/carts', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(cart) }) .then(response => response.json()) .then(data => console.log(data)); ``` ```nodejs const axios = require('axios'); const cart = { userId: 1, products: [{ id: 1 }] }; axios.post('https://fakestoreapi.com/carts', cart) .then(response => console.log(response.data)); ``` ```php 1, 'products' => [['id' => 1]]]); $ch = curl_init('https://fakestoreapi.com/carts'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $cart); ``` -------------------------------- ### Login Success Response Source: https://fakestoreapi.com/docs The JSON structure returned upon a successful authentication. ```json { * "token": "string" } ``` -------------------------------- ### Update product with PUT - JavaScript, Node.js, PHP, cURL Source: https://fakestoreapi.com/docs-data Update an existing product by ID using the PUT method. The request body must contain the product fields to update, and the response returns the updated product. The id parameter is required in the path. ```javascript fetch('https://fakestoreapi.com/products/1', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(product) }) .then(response => response.json()) .then(data => console.log(data)); ``` ```nodejs const axios = require('axios'); const product = { title: 'Updated Product', price: 39.99 }; axios.put('https://fakestoreapi.com/products/1', product) .then(response => console.log(response.data)); ``` ```php 'Updated Product', 'price' => 39.99]); $ch = curl_init('https://fakestoreapi.com/products/1'); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($ch, CURLOPT_POSTFIELDS, $product); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); $response = curl_exec($ch); curl_close($ch); echo $response; ?> ``` ```curl curl -X PUT 'https://fakestoreapi.com/products/1' -H 'Content-Type: application/json' -d '{"title": "Updated Product", "price": 39.99}' ``` -------------------------------- ### Create a new cart via cURL Source: https://fakestoreapi.com/docs-data Sends a POST request to create a new cart with a specific user ID and product list. ```curl curl -X POST 'https://fakestoreapi.com/carts' -H 'Content-Type: application/json' -d '{"userId": 1, "products": [{"id": 1}]}' ``` -------------------------------- ### Update a user by ID with JavaScript (Browser) Source: https://fakestoreapi.com/docs-data Update an existing user by ID using a PUT request. The path parameter 'id' is required. The request body should contain the fields to update. A successful update returns a 200 status with the updated user object. ```javascript const user = { username: 'john_doe_updated', email: 'john.updated@example.com' }; fetch('https://fakestoreapi.com/users/1', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(user) }) .then(response => response.json()) .then(data => ``` -------------------------------- ### Add a new user payload Source: https://fakestoreapi.com/docs The JSON structure required to create a new user. ```json { "id": 0, "username": "string", "email": "string", "password": "string" } ``` -------------------------------- ### Delete product with DELETE - JavaScript, Node.js, PHP, cURL, Python Source: https://fakestoreapi.com/docs-data Delete a specific product by ID using the DELETE method. The id parameter is required in the path. A successful deletion returns a 200 response, while a bad request returns 400. ```javascript fetch('https://fakestoreapi.com/products/1', { method: 'DELETE' }) .then(response => response.json()) .then(data => console.log(data)); ``` ```nodejs const axios = require('axios'); axios.delete('https://fakestoreapi.com/products/1') .then(response => console.log(response.data)); ``` ```php ``` ```curl curl -X DELETE 'https://fakestoreapi.com/products/1' ``` ```python import requests response = requests.delete('https://fakestoreapi.com/products/1') print(response.json()) ``` -------------------------------- ### Delete a product using fetch Source: https://fakestoreapi.com/docs Deletes a specific product by its ID using the DELETE method. ```javascript fetch('https://fakestoreapi.com/products/1', { method: 'DELETE' }) .then(response => response.json()) .then(data => console.log(data)); ``` -------------------------------- ### Product response schema Source: https://fakestoreapi.com/docs The JSON structure returned by the API for product queries. ```json [ { "id": 0, "title": "string", "price": 0.1, "description": "string", "category": "string", "image": "http://example.com" } ] ``` -------------------------------- ### Delete a user with DELETE /users/{id} Source: https://fakestoreapi.com/docs-data Delete a user by ID. The endpoint requires an integer ID in the path. Successful deletion returns a 200 response; a bad request returns 400. ```javascript fetch('https://fakestoreapi.com/users/1', { method: 'DELETE' }) .then(response => response.json()) .then(data => console.log(data)); ``` ```nodejs const axios = require('axios'); axios.delete('https://fakestoreapi.com/users/1') .then(response => console.log(response.data)); ``` ```php ``` ```curl curl -X DELETE 'https://fakestoreapi.com/users/1' ``` ```python import requests response = requests.delete('https://fakestoreapi.com/users/1') print(response.json()) ``` -------------------------------- ### DELETE /products/{id} Source: https://fakestoreapi.com/docs Deletes a specific product by its ID. The endpoint accepts a path parameter for the product ID and returns a success or error response. ```APIDOC ## DELETE /products/{id} ### Description Delete a specific product by ID. ### Method DELETE ### Endpoint https://fakestoreapi.com/products/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the product to delete. ### Responses #### Success Response (200) Product deleted successfully #### Error Response (400) Bad request ### Request Example ``` fetch('https://fakestoreapi.com/products/1', { method: 'DELETE' }) .then(response => response.json()) .then(data => console.log(data)); ``` ``` -------------------------------- ### Add a new product request payload Source: https://fakestoreapi.com/docs The JSON structure required to create a new product via a POST request. ```json { "id": 0, "title": "string", "price": 0.1, "description": "string", "category": "string", "image": "http://example.com" } ``` -------------------------------- ### User response schema Source: https://fakestoreapi.com/docs The JSON structure returned for a successful user request. ```json { * "id": 0, * "username": "string", * "email": "string", * "password": "string" } ``` -------------------------------- ### Update a cart via Node.js Source: https://fakestoreapi.com/docs-data Updates an existing cart using the Axios library. ```nodejs const axios = require('axios'); const cart = { userId: 1, products: [{ id: 2 }] }; axios.put('https://fakestoreapi.com/carts/1', cart) .then(response => console.log(response.data)); ``` -------------------------------- ### Update a cart via Python Source: https://fakestoreapi.com/docs-data Updates an existing cart using the requests library. ```python import requests cart = {'userId': 1, 'products': [{'id': 2}]} response = requests.put('https://fakestoreapi.com/carts/1', json=cart) print(response.json()) ``` -------------------------------- ### Update a cart via JavaScript Source: https://fakestoreapi.com/docs-data Updates an existing cart using the fetch API with a PUT method. ```javascript const cart = { userId: 1, products: [{ id: 2 }] }; fetch('https://fakestoreapi.com/carts/1', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(cart) }) .then(response => response.json()) .then(data => console.log(data)); ``` -------------------------------- ### Delete a cart via Node.js Source: https://fakestoreapi.com/docs-data Deletes a cart using the Axios library. ```nodejs const axios = require('axios'); axios.delete('https://fakestoreapi.com/carts/1') .then(response => console.log(response.data)); ``` -------------------------------- ### PUT /users/{id} Source: https://fakestoreapi.com/docs-data Updates an existing user by ID with the provided fields. ```APIDOC ## PUT /users/{id} ### Description Update an existing user by ID. ### Method PUT ### Endpoint https://fakestoreapi.com/users/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the user to update. #### Request Body - **username** (string) - Optional - The updated username. - **email** (string) - Optional - The updated email address. ### Response #### Success Response (200) - Returns the updated User object. #### Error Response (400) - Bad request ``` -------------------------------- ### PUT /users/{id} Source: https://fakestoreapi.com/docs-data Updates an existing user by ID. The request body must contain the fields to update, and the response returns the updated user object. ```APIDOC ## PUT /users/{id} ### Description Update a specific user by ID. ### Method PUT ### Endpoint https://fakestoreapi.com/users/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the user to update. #### Request Body - **username** (string) - Required - The new username. - **email** (string) - Required - The new email. ### Request Example { "username": "john_doe_updated", "email": "john.updated@example.com" } ### Response #### Success Response (200) - **id** (integer) - The user ID. - **username** (string) - The updated username. - **email** (string) - The updated email. #### Response Example { "id": 1, "username": "john_doe_updated", "email": "john.updated@example.com" } #### Error Response (400) - **message** (string) - Error description. ### Code Samples #### JavaScript (Browser) ```javascript fetch('https://fakestoreapi.com/users/1', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username: 'john_doe_updated', email: 'john.updated@example.com' }) }) .then(response => response.json()) .then(data => console.log(data)); ``` #### Node.js (Axios) ```javascript const axios = require('axios'); const user = { username: 'john_doe_updated', email: 'john.updated@example.com' }; axios.put('https://fakestoreapi.com/users/1', user) .then(response => console.log(response.data)); ``` #### PHP ```php 'john_doe_updated', 'email' => 'john.updated@example.com']); $ch = curl_init('https://fakestoreapi.com/users/1'); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($ch, CURLOPT_POSTFIELDS, $user); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); $response = curl_exec($ch); curl_close($ch); echo $response; ?> ``` #### cURL ```bash curl -X PUT 'https://fakestoreapi.com/users/1' -H 'Content-Type: application/json' -d '{"username": "john_doe_updated", "email": "john.updated@example.com"}' ``` #### Python ```python import requests user = {'username': 'john_doe_updated', 'email': 'john.updated@example.com'} response = requests.put('https://fakestoreapi.com/users/1', json=user) print(response.json()) ``` ``` -------------------------------- ### Update a cart via PHP Source: https://fakestoreapi.com/docs-data Updates an existing cart using cURL with a PUT request. ```php 1, 'products' => [['id' => 2]]]); $ch = curl_init('https://fakestoreapi.com/carts/1'); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($ch, CURLOPT_POSTFIELDS, $cart); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); $response = curl_exec($ch); curl_close($ch); echo $response; ?> ``` -------------------------------- ### DELETE /users/{id} Source: https://fakestoreapi.com/docs-data Deletes a specific user by ID. The response confirms the deletion with a success message. ```APIDOC ## DELETE /users/{id} ### Description Delete a specific user by ID. ### Method DELETE ### Endpoint https://fakestoreapi.com/users/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the user to delete. ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example { "message": "User deleted successfully" } #### Error Response (400) - **message** (string) - Error description. ### Code Samples #### JavaScript (Browser) ```javascript fetch('https://fakestoreapi.com/users/1', { method: 'DELETE' }) .then(response => response.json()) .then(data => console.log(data)); ``` #### Node.js (Axios) ```javascript const axios = require('axios'); axios.delete('https://fakestoreapi.com/users/1') .then(response => console.log(response.data)); ``` #### PHP ```php ``` #### cURL ```bash curl -X DELETE 'https://fakestoreapi.com/users/1' ``` #### Python ```python import requests response = requests.delete('https://fakestoreapi.com/users/1') print(response.json()) ``` ``` -------------------------------- ### Cart response schema Source: https://fakestoreapi.com/docs The JSON structure returned for a successful cart request. ```json { * "id": 0, * "userId": 0, * "products": [ * { * "id": 0, * "title": "string", * "price": 0.1, * "description": "string", * "category": "string", * "image": "http://example.com" } ] } ``` -------------------------------- ### Delete a user with fetch Source: https://fakestoreapi.com/docs Remove a specific user by ID using the DELETE method with the fetch API. ```javascript fetch('https://fakestoreapi.com/users/1', { method: 'DELETE' }) .then(response => response.json()) .then(data => console.log(data)); ``` -------------------------------- ### Update a cart via cURL Source: https://fakestoreapi.com/docs-data Updates an existing cart using a PUT request. ```curl curl -X PUT 'https://fakestoreapi.com/carts/1' -H 'Content-Type: application/json' -d '{"userId": 1, "products": [{"id": 2}]}' ``` -------------------------------- ### Login Request Payload Source: https://fakestoreapi.com/docs The JSON structure required for the authentication request body. ```json { * "username": "string", * "password": "string" } ``` -------------------------------- ### Add a new cart request payload Source: https://fakestoreapi.com/docs The JSON structure required to create a new cart. ```json { "id": 0, "userId": 0, "products": [ { "id": 0, "title": "string", "price": 0.1, "description": "string", "category": "string", "image": "http://example.com" } ] } ``` -------------------------------- ### PUT /carts/{id} Source: https://fakestoreapi.com/docs-data Updates an existing cart by ID. ```APIDOC ## PUT /carts/{id} ### Description Updates an existing cart by ID. ### Method PUT ### Endpoint https://fakestoreapi.com/carts/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the cart to update. #### Request Body - **userId** (integer) - Required - The ID of the user who owns the cart. - **products** (array) - Required - An array of product objects, each containing an **id** (integer) of the product. ### Request Example { "userId": 1, "products": [ { "id": 2 } ] } ### Response #### Success Response (200) - **id** (integer) - The ID of the updated cart. - **userId** (integer) - The ID of the user who owns the cart. - **date** (string) - The date the cart was updated. - **products** (array) - An array of product objects, each containing **productId** (integer) and **quantity** (integer). #### Response Example { "id": 1, "userId": 1, "date": "2020-02-03T12:00:00.000Z", "products": [ { "productId": 2, "quantity": 1 } ] } #### Error Response (400) Bad request - invalid input data. ``` -------------------------------- ### Delete a cart via JavaScript Source: https://fakestoreapi.com/docs-data Deletes a cart using the fetch API with a DELETE method. ```javascript fetch('https://fakestoreapi.com/carts/1', { method: 'DELETE' }) .then(response => response.json()) .then(data => console.log(data)); ``` -------------------------------- ### Delete a cart via PHP Source: https://fakestoreapi.com/docs-data Deletes a cart using cURL with a DELETE request. ```php ``` -------------------------------- ### Delete a cart via cURL Source: https://fakestoreapi.com/docs-data Deletes a cart using a DELETE request. ```curl curl -X DELETE 'https://fakestoreapi.com/carts/1' ``` -------------------------------- ### DELETE /carts/{id} Source: https://fakestoreapi.com/docs-data Deletes a specific cart by its ID. ```APIDOC ## DELETE /carts/{id} ### Description Deletes a specific cart by ID. ### Method DELETE ### Endpoint https://fakestoreapi.com/carts/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the cart to delete. ### Response #### Success Response (200) - Cart deleted successfully #### Error Response (400) - Bad request ``` -------------------------------- ### DELETE /carts/{id} Source: https://fakestoreapi.com/docs-data Deletes a specific cart by ID. ```APIDOC ## DELETE /carts/{id} ### Description Deletes a specific cart by ID. ### Method DELETE ### Endpoint https://fakestoreapi.com/carts/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the cart to delete. ### Response #### Success Response (200) - **id** (integer) - The ID of the deleted cart. - **userId** (integer) - The ID of the user who owned the cart. - **date** (string) - The date the cart was created. - **products** (array) - An array of product objects, each containing **productId** (integer) and **quantity** (integer). #### Response Example { "id": 1, "userId": 1, "date": "2020-02-03T12:00:00.000Z", "products": [ { "productId": 1, "quantity": 1 } ] } #### Error Response (400) Bad request - invalid ID. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.