DummyJSON

repository·master·Indexed 25 days ago

https://github.com/ovi/dummyjson

A free REST API for generating placeholder JSON data, designed for UI testing, prototyping, and learning. It provides endpoints for products, carts, posts, and comments, and includes a Dummy Image Generator and identicon service. The API supports filtering, pagination, and simulated network latency via query parameters.

Tokens
4.4K
Snippets
5
Records
57
Agent score
83%

What's inside dummyjson

  1. Fetch data from DummyJSON

    master

    DummyJSON provides a free REST API for generating placeholder JSON data. You can use any HTTP client (fetch API, Axios, etc.) to access resources. The API supports all HTTP methods and includes built-in pagination.

    // Using fetch API
    const res = await fetch('https://dummyjson.com/products');
    const json = await res.json();
    console.log(json);
  2. Start the DummyJSON API server

    master

    The DummyJSON server can be started by running the entrypoint script. It initializes the Express application, connects to the database, sets up CRON jobs, loads data into memory, and configures middleware and routes.

    By default, the server listens on port 8888. You can configure the server using the following environment variables:

    • PORT: The port number to listen on (default: 8888).
    • NODE_ENV: The current environment (e.g., development, production).
    • GOOGLE_TAG_ID: Used for tracking in the 404 error view.
    • BANNER_CONTENT: Content displayed in the 404 error view.
  3. Use the Dummy Image Generator

    master

    The Dummy Image Generator is a service for creating placeholder images via HTTP requests. You can customize the size, background colors, text, and fonts.

    URL Pattern: https://dummyjson.com/image/{SIZE}/{BG_COLOR}/{TEXT_COLOR}?text={TEXT}&fontFamily={FONT}&fontSize={SIZE}

    https://dummyjson.com/image/300/da5047/030104?text=Hello+Peter&fontFamily=cookie&fontSize=36
  4. Configure required and optional environment variables

    master

    When setting up the DummyJSON environment, ensure the following environment variables are configured:

    Required Variables:

    • JWT_SECRET
    • MONGODB_URI

    Optional Variables:

    • MONGODB_DB_NAME
    • GOOGLE_TAG_ID
    • GOOGLE_ADS_TXT_CONTENT
    • AWS_ACCESS_KEY
    • AWS_SECRET_KEY
    • AWS_BUCKET_NAME
    • LOG_ENABLED
    • BANNER_CONTENT
    • STATS
  5. Access nested resources

    master

    DummyJSON supports accessing nested resources via the URL path. For example, you can fetch all posts belonging to a specific user by appending the resource name to the user's endpoint.

    https://dummyjson.com/users/1/posts
  6. Configure fonts for Dummy Image Generator

    master

    When using the Dummy Image Generator, you can specify one of the following supported fonts using the fontFamily parameter:

    • Bitter
    • Cairo
    • Comfortaa
    • Cookie
    • Dosis
    • Gotham
    • Lobster
    • Marhey
    • Pacifico
    • Poppins
    • Quicksand
    • Qwigley
    • Satisfy
    • Ubuntu
  7. Use filtering, pagination, and delays in API requests

    master

    You can manipulate DummyJSON API responses using query parameters:

    • Filtering & Search: Use the search?q= parameter to find specific items.
    • Pagination: Use limit and skip parameters to control the number of results and the offset.
    • Delay Responses: Use the delay parameter (in milliseconds) to simulate network latency.
    https://dummyjson.com/products/search?q=phone
    https://dummyjson.com/products?limit=10&skip=10
    https://dummyjson.com/products?delay=1000