httpclient

package
v0.0.0-...-678b47c Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package httpclient provides a client for working with HTTP requests, using a method based API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(r *http.Response, val interface{}) error

Types

type Client

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

func New

func New(client *http.Client, base string) *Client

func (*Client) Delete

func (c *Client) Delete(url string, mw ...ClientMiddleware) (*http.Response, error)

func (*Client) Do

func (c *Client) Do(req *http.Request, rmw []ClientMiddleware) (*http.Response, error)

func (*Client) Get

func (c *Client) Get(url string, mw ...ClientMiddleware) (*http.Response, error)

func (*Client) Path

func (c *Client) Path(url string) string

Path will safely join the base URL and the provided path and return a string that can be used in a request.

func (*Client) Pathf

func (c *Client) Pathf(url string, v ...any) string

Pathf will call fmt.Sprintf with the provided values and then pass them to Client.Path as a convenience.

func (*Client) Post

func (c *Client) Post(url string, payload []byte, mw ...ClientMiddleware) (*http.Response, error)

func (*Client) Put

func (c *Client) Put(url string, payload []byte, mw ...ClientMiddleware) (*http.Response, error)

func (*Client) Use

func (c *Client) Use(mws ...ClientMiddleware)

type ClientMiddleware

type ClientMiddleware = func(*http.Request) (*http.Request, error)

func MwBearerToken

func MwBearerToken(token string) ClientMiddleware

MwBearerToken adds an Authorization header with the 'token' prefix.

Example "Authorization: token abc123"

func MwContentType

func MwContentType(contentType string) ClientMiddleware

Jump to

Keyboard shortcuts

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