request

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 5 Imported by: 0

README

request

Documentation

Overview

Package request provides a small generic helper for sending HTTP requests and decoding JSON responses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Send

func Send[T any](opts Options) (*T, error)

Send performs opts and decodes the response body into *T.

It returns an error if the request cannot be built or sent, if the server replies with a non-2xx status, or if the response body cannot be decoded as JSON.

Types

type Auth added in v0.1.1

type Auth interface {
	// contains filtered or unexported methods
}

Auth is implemented by any value that can apply credentials to an outgoing http.Request (e.g. BasicAuth).

type BasicAuth added in v0.1.1

type BasicAuth struct {
	Username string
	Password string
}

BasicAuth adds HTTP Basic credentials to the request.

type BearerAuth added in v0.1.1

type BearerAuth struct {
	Token string
}

BearerAuth adds an Authorization: Bearer <token> header to the request.

type Options added in v0.1.1

type Options struct {
	Method  string
	Url     string
	Body    any
	Headers map[string]string
	Auth    Auth
}

Options describes a single HTTP request.

Body can be any value that json.Marshal can handle. If it is nil, an empty request body is sent. If it is already a []byte or io.Reader, it is used as-is (without re-encoding).

Headers is merged on top of the Content-Type that the package sets for JSON bodies, so callers can override it.

Jump to

Keyboard shortcuts

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