jsonplaceholder

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package jsonplaceholder is the library behind the jsonplaceholder command line: the HTTP client, request shaping, and the typed data models for the JSONPlaceholder fake REST API at https://jsonplaceholder.typicode.com.

The API is public and requires no key. It provides fake posts, comments, users, todos, albums, and photos for testing and prototyping.

Index

Constants

View Source
const DefaultUserAgent = "jsonplaceholder-cli/0.1.0 (github.com/tamnd/jsonplaceholder-cli)"

DefaultUserAgent identifies the client to the API.

View Source
const Host = "jsonplaceholder.typicode.com"

Host is the JSONPlaceholder API hostname.

Variables

This section is empty.

Functions

This section is empty.

Types

type Album

type Album struct {
	ID     int    `json:"id"`
	UserID int    `json:"userId"`
	Title  string `json:"title"`
}

Album is a photo album.

type Client

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

Client is the JSONPlaceholder HTTP client.

func NewClient

func NewClient(cfg Config) *Client

NewClient constructs a Client from cfg.

func (*Client) Albums

func (c *Client) Albums(ctx context.Context, userID, limit int) ([]Album, error)

Albums returns albums filtered by optional userId and limit.

func (*Client) Comments

func (c *Client) Comments(ctx context.Context, postID int) ([]Comment, error)

Comments returns comments on a given post.

func (*Client) Photos

func (c *Client) Photos(ctx context.Context, albumID, limit int) ([]Photo, error)

Photos returns photos filtered by optional albumId and limit.

func (*Client) Post

func (c *Client) Post(ctx context.Context, id int) (Post, error)

Post returns a single post by id.

func (*Client) Posts

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

Posts returns a list of posts filtered by optional userId and limit. Zero values are omitted from the query.

func (*Client) Todos

func (c *Client) Todos(ctx context.Context, userID, limit int, completed, completedSet bool) ([]Todo, error)

Todos returns todos filtered by optional userId, completed flag, and limit. completedSet indicates whether the completed filter should be applied.

func (*Client) User

func (c *Client) User(ctx context.Context, id int) (User, error)

User returns a single user by id.

func (*Client) Users

func (c *Client) Users(ctx context.Context) ([]User, error)

Users returns all users.

type Comment

type Comment struct {
	ID     int    `json:"id"`
	PostID int    `json:"postId"`
	Name   string `json:"name"`
	Email  string `json:"email"`
	Body   string `json:"body"`
}

Comment is a comment on a post.

type Config

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

Config holds constructor parameters for Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns production defaults.

type Domain

type Domain struct{}

Domain is the jsonplaceholder driver.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns any accepted input into the canonical (type, id).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

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

Locate is the inverse: 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 Photo

type Photo struct {
	ID           int    `json:"id"`
	AlbumID      int    `json:"albumId"`
	Title        string `json:"title"`
	URL          string `json:"url"`
	ThumbnailURL string `json:"thumbnailUrl"`
}

Photo is a photo within an album.

type Post

type Post struct {
	ID     int    `json:"id"`
	UserID int    `json:"userId"`
	Title  string `json:"title"`
	Body   string `json:"body"`
}

Post is a JSONPlaceholder blog post.

type Todo

type Todo struct {
	ID        int    `json:"id"`
	UserID    int    `json:"userId"`
	Title     string `json:"title"`
	Completed bool   `json:"completed"`
}

Todo is a task item.

type User

type User struct {
	ID       int    `json:"id"`
	Name     string `json:"name"`
	Username string `json:"username"`
	Email    string `json:"email"`
	Phone    string `json:"phone"`
	Website  string `json:"website"`
	City     string `json:"city"`    // from address.city
	Company  string `json:"company"` // from company.name
}

User is a JSONPlaceholder user with flattened address and company fields.

Jump to

Keyboard shortcuts

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