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 ¶
- type Client
- func (c Client) Create(ctx context.Context, resourcePath string, input, output interface{}) error
- func (c Client) Do(request *http.Request, output interface{}) error
- func (c Client) NewRequest(ctx context.Context, method, resourcePath string, query url.Values, ...) (*http.Request, error)
- func (c Client) Read(ctx context.Context, resourcePath string, output interface{}) error
- func (c Client) ReadWithQuery(ctx context.Context, resourcePath string, query url.Values, output interface{}) error
- func (c Client) Update(ctx context.Context, resourcePath string, input, output interface{}) error
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
// Host allows to set a specific host header. This is useful
// to implement, e.g., cloudfronting.
Host string
// Logger is the logger to use.
Logger model.Logger
// ProxyURL allows to force a proxy URL to fallback to a
// tunnel, e.g., Psiphon.
ProxyURL *url.URL
// UserAgent is the user agent to use.
UserAgent string
}
Client is a client for a JSON API.
func (Client) Create ¶
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) Do ¶ added in v0.12.0
Do performs the provided request and unmarshals the JSON response body into the provided output variable.
func (Client) NewRequest ¶ added in v0.12.0
func (c Client) NewRequest( ctx context.Context, method, resourcePath string, query url.Values, body interface{}) (*http.Request, error)
NewRequest creates a new request with a JSON body
func (Client) Read ¶
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.