jsonapi

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2020 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package jsonapi interacts with HTTP JSON APIs. In OONI we use this code when accessing API like, e.g., the OONI collector.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// Authorization contains the authorization header.
	Authorization string

	// BaseURL is the base URL of the API.
	BaseURL string

	// HTTPClient is the http client to use.
	HTTPClient *http.Client

	// Logger is the logger to use.
	Logger model.Logger

	// UserAgent is the user agent to use.
	UserAgent string
}

Client is a client for a JSON API.

func (*Client) Create

func (c *Client) Create(
	ctx context.Context, resourcePath string, input, output interface{},
) error

Create creates a JSON subresource of the resource at resourcePath using the JSON document at input and returning the result into the JSON document at output. The request is bounded by the context's lifetime. Returns the error that occurred.

func (*Client) Read

func (c *Client) Read(
	ctx context.Context, resourcePath string, output interface{},
) error

Read reads the JSON resource at resourcePath and unmarshals the results into output. The request is bounded by the lifetime of the context passed as argument. Returns the error that occurred.

func (*Client) ReadWithQuery

func (c *Client) ReadWithQuery(
	ctx context.Context, resourcePath string,
	query url.Values, output interface{},
) error

ReadWithQuery is like Read but also has a query.

func (*Client) Update

func (c *Client) Update(
	ctx context.Context, resourcePath string, input, output interface{},
) error

Update updates a JSON resource at a specific path and returns the error that occurred and possibly an output document

Jump to

Keyboard shortcuts

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