dummyjson

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package dummyjson is the library behind the dummyjson command line: the HTTP client, request shaping, and typed data models for the DummyJSON API (https://dummyjson.com/).

No API key is required. The Client paces requests, sets a real User-Agent, and retries transient failures (429 and 5xx).

Index

Constants

View Source
const BaseURL = "https://" + Host

BaseURL is the root every API request is built from.

View Source
const DefaultUserAgent = "dummyjson-cli/0.1 (tamnd87@gmail.com)"

DefaultUserAgent identifies the client to DummyJSON.

View Source
const Host = "dummyjson.com"

Host is the API hostname.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category added in v0.1.1

type Category struct {
	Slug string `kit:"id" json:"slug"`
	Name string `json:"name"`
}

Category is a DummyJSON product category.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to the DummyJSON API.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client with the given configuration.

func (*Client) ListCategories added in v0.1.1

func (c *Client) ListCategories(ctx context.Context) ([]Category, error)

ListCategories fetches the list of product categories.

func (*Client) ListPosts added in v0.1.1

func (c *Client) ListPosts(ctx context.Context, limit int) ([]Post, int, error)

ListPosts fetches a page of posts.

func (*Client) ListProducts added in v0.1.1

func (c *Client) ListProducts(ctx context.Context, category string, limit int) ([]Product, int, error)

ListProducts fetches products, optionally filtered by category.

func (*Client) ListQuotes added in v0.1.1

func (c *Client) ListQuotes(ctx context.Context, limit int) ([]Quote, int, error)

ListQuotes fetches a page of quotes.

func (*Client) ListRecipes added in v0.1.1

func (c *Client) ListRecipes(ctx context.Context, limit int) ([]Recipe, int, error)

ListRecipes fetches a page of recipes.

func (*Client) ListUsers added in v0.1.1

func (c *Client) ListUsers(ctx context.Context, limit int) ([]User, int, error)

ListUsers fetches a page of users.

func (*Client) SearchProducts added in v0.1.1

func (c *Client) SearchProducts(ctx context.Context, q string, limit int) ([]Product, int, error)

SearchProducts searches products by query string.

type Config added in v0.1.1

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Timeout   time.Duration
	Retries   int
}

Config holds all tunable parameters for the Client.

func DefaultConfig added in v0.1.1

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type Domain

type Domain struct{}

Domain is the dummyjson driver.

func (Domain) Classify

func (Domain) Classify(input string) (string, string, error)

Classify turns an identifier into (type, id). Numeric input -> ("product", input); otherwise -> ("query", input).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, hostnames, and binary identity.

func (Domain) Locate

func (Domain) Locate(t, id string) (string, error)

Locate returns the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type Post added in v0.1.1

type Post struct {
	ID     int    `kit:"id" json:"id"`
	Title  string `json:"title"`
	Tags   string `json:"tags"`
	Views  int    `json:"views"`
	Likes  int    `json:"likes"`
	UserID int    `json:"user_id"`
}

Post is a DummyJSON post record.

type Product added in v0.1.1

type Product struct {
	ID       int     `kit:"id" json:"id"`
	Title    string  `json:"title"`
	Category string  `json:"category"`
	Brand    string  `json:"brand"`
	Price    float64 `json:"price"`
	Rating   float64 `json:"rating"`
	Stock    int     `json:"stock"`
}

Product is a DummyJSON product record.

type Quote added in v0.1.1

type Quote struct {
	ID     int    `kit:"id" json:"id"`
	Quote  string `json:"quote"`
	Author string `json:"author"`
}

Quote is a DummyJSON quote record.

type Recipe added in v0.1.1

type Recipe struct {
	ID         int    `kit:"id" json:"id"`
	Name       string `json:"name"`
	Cuisine    string `json:"cuisine"`
	Difficulty string `json:"difficulty"`
	PrepTime   int    `json:"prep_time"`
	CookTime   int    `json:"cook_time"`
	Servings   int    `json:"servings"`
	Calories   int    `json:"calories"`
}

Recipe is a DummyJSON recipe record.

type User added in v0.1.1

type User struct {
	ID        int    `kit:"id" json:"id"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Email     string `json:"email"`
	Age       int    `json:"age"`
	Gender    string `json:"gender"`
	Username  string `json:"username"`
	City      string `json:"city"`
	Country   string `json:"country"`
}

User is a DummyJSON user record.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL