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
- type Album
- type Client
- func (c *Client) Albums(ctx context.Context, userID, limit int) ([]Album, error)
- func (c *Client) Comments(ctx context.Context, postID int) ([]Comment, error)
- func (c *Client) Photos(ctx context.Context, albumID, limit int) ([]Photo, error)
- func (c *Client) Post(ctx context.Context, id int) (Post, error)
- func (c *Client) Posts(ctx context.Context, userID, limit int) ([]Post, error)
- func (c *Client) Todos(ctx context.Context, userID, limit int, completed, completedSet bool) ([]Todo, error)
- func (c *Client) User(ctx context.Context, id int) (User, error)
- func (c *Client) Users(ctx context.Context) ([]User, error)
- type Comment
- type Config
- type Domain
- type Photo
- type Post
- type Todo
- type User
Constants ¶
const DefaultUserAgent = "jsonplaceholder-cli/0.1.0 (github.com/tamnd/jsonplaceholder-cli)"
DefaultUserAgent identifies the client to the API.
const Host = "jsonplaceholder.typicode.com"
Host is the JSONPlaceholder API hostname.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the JSONPlaceholder HTTP client.
func (*Client) Posts ¶
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.
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.
type Domain ¶
type Domain struct{}
Domain is the jsonplaceholder driver.
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.
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.