Categorygithub.com/blizzy78/gojsonclient
modulepackage
0.5.1
Repository: https://github.com/blizzy78/gojsonclient.git
Documentation: pkg.go.dev

# README

GoDoc

gojsonclient

A Go package that provides a client for JSON/REST HTTP services, with automatic retry/backoff.

import "github.com/blizzy78/gojsonclient"

Code example

type request struct {
	Message string `json:"message"`
}

type response struct {
	Reply string `json:"reply"`
}

client := New()

req := NewRequest[*request, *response]("https://www.example.com", http.MethodGet, &request{
	Message: "client",
})

res, _ := Do(context.Background(), client, req)
fmt.Println(res.Res.Reply)

// Output: Hello client!

License

This package is licensed under the MIT license.

# Functions

BasicAuth returns a request middleware that sets the request's Authorization header to use HTTP Basic authentication with the provided username and password.
BearerAuth returns a request middleware that sets the request's Authorization header to use HTTP Bearer authentication with the provided token.
Do executes req with client and returns the response.
New creates a new Client with the given options.
NewRequest creates a new Request with the given client, URI, method, request data, and options.
WithBackoff configures a Client to use backoff.
WithBaseURI configures a Client to use baseURI as the URI prefix for all requests.
WithHTTPClient configures a Client to use httpClient to make requests.
WithIgnoreResponseBody configures a Request to ignore the response body, regardless of status code.
WithLogger configures a Client to use logger.
WithMarshalRequestFunc configures a Request to use fun as the marshal function.
WithMaxAttempts configures a Client to make at most max attempts for each request.
WithRequestMiddleware configures a Client to use fun as a request middleware.
WithRequestTimeout configures a Client to use timeout for each HTTP request made.
WithRetry configures a Client to use retry as the retry function.
WithUnmarshalResponseFunc configures a Request to use fun as the unmarshal function.

# Structs

Client is a client for JSON/REST HTTP services.
Request represents a JSON/REST HTTP request.
Response represents a JSON/REST HTTP response.

# Type aliases

ClientOpt is a function that configures a Client.
MarshalJSONFunc is a function that encodes a value to JSON and outputs it to writer.
RequestMiddlewareFunc is a function that modifies an HTTP request.
RequestOpt is a function that configures a Request.
RetryFunc is a function that decides whether to retry an HTTP request.
UnmarshalJSONFunc is a function that decodes JSON from httpRes.Body and stores it in val.