httpx

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

httpx

A lightweight HTTP extension for Go that eliminates REST boilerplate with idiomatic binders, responders, middlewares, and testing helpers.

Documentation

Index

Constants

View Source
const (
	HeaderContentType          = "Content-Type"
	HeaderContentLength        = "Content-Length"
	HeaderContentEncoding      = "Content-Encoding"
	HeaderAuthorization        = "Authorization"
	HeaderOrigin               = "Origin"
	HeaderUserAgent            = "User-Agent"
	HeaderAccept               = "Accept"
	HeaderAcceptLanguage       = "Accept-Language"
	HeaderCookie               = "Cookie"
	HeaderSetCookie            = "Set-Cookie"
	HeaderLocation             = "Location"
	HeaderReferer              = "Referer"
	HeaderHost                 = "Host"
	HeaderCacheControl         = "Cache-Control"
	HeaderETag                 = "ETag"
	HeaderLastModified         = "Last-Modified"
	HeaderIfNoneMatch          = "If-None-Match"
	HeaderIfModifiedSince      = "If-Modified-Since"
	HeaderVary                 = "Vary"
	HeaderCORSAllowOrigin      = "Access-Control-Allow-Origin"
	HeaderCORSAllowMethods     = "Access-Control-Allow-Methods"
	HeaderCORSAllowHeaders     = "Access-Control-Allow-Headers"
	HeaderCORSExposeHeaders    = "Access-Control-Expose-Headers"
	HeaderCORSMaxAge           = "Access-Control-Max-Age"
	HeaderCORSAllowCredentials = "Access-Control-Allow-Credentials"
	HeaderCORSRequestMethod    = "Access-Control-Request-Method"
	HeaderCORSRequestHeaders   = "Access-Control-Request-Headers"
	HeaderXRequestID           = "X-Request-ID"
	HeaderXForwardedFor        = "X-Forwarded-For"
	HeaderXRealIP              = "X-Real-IP"
	HeaderXForwardedProto      = "X-Forwarded-Proto"
	HeaderXForwardedHost       = "X-Forwarded-Host"
)
View Source
const (
	ContentTypeJSON        = "application/json; charset=utf-8"
	ContentTypeText        = "text/plain; charset=utf-8"
	ContentTypeHTML        = "text/html; charset=utf-8"
	ContentTypeFormData    = "application/x-www-form-urlencoded"
	ContentTypeMultipart   = "multipart/form-data"
	ContentTypeOctetStream = "application/octet-stream"
)

Variables

View Source
var (
	ErrBodyTooLarge = errors.New("request body too large")
	ErrBodyInvalid  = errors.New("invalid json")
)

Functions

func ClientIP

func ClientIP(r *http.Request) string

func NewErrInvalidPathParam

func NewErrInvalidPathParam(paramName string) error

func NewErrInvalidQueryParam

func NewErrInvalidQueryParam(paramName string) error

func ParsePathParamAs

func ParsePathParamAs[T any](r *http.Request, name string) (T, error)

func ParsePathParamOrAs

func ParsePathParamOrAs[T any](r *http.Request, name string, defaultValue T) (T, error)

func ParseQueryParamAs

func ParseQueryParamAs[T any](r *http.Request, name string) (T, error)

func ParseQueryParamOrAs

func ParseQueryParamOrAs[T any](r *http.Request, name string, defaultValue T) (T, error)

func ParseValueAs

func ParseValueAs[T any](value string) (T, error)

Types

type Binder

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

func NewBinder

func NewBinder(opts ...BinderOption) *Binder

func (*Binder) JSON

func (b *Binder) JSON(r *http.Request, i any) error

type BinderOption

type BinderOption func(b *Binder)

func WithBodyMaxSize

func WithBodyMaxSize(maxBodySize int64) BinderOption

type EmptyResponse

type EmptyResponse struct{}

type ErrConverter

type ErrConverter func(err error, l *slog.Logger) (statusCode int, i any)

type ErrInvalidParam

type ErrInvalidParam struct {
	ParamType string
	ParamName string
}

func (*ErrInvalidParam) Error

func (e *ErrInvalidParam) Error() string

type ErrResponse

type ErrResponse struct {
	Message string `json:"message,omitempty"`
}

type Responder

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

func NewResponder

func NewResponder(opts ...ResponderOption) *Responder

func (*Responder) Created

func (r *Responder) Created(w http.ResponseWriter, i any)

func (*Responder) EmptyOK

func (r *Responder) EmptyOK(w http.ResponseWriter)

func (*Responder) Error

func (r *Responder) Error(w http.ResponseWriter, err error)

func (*Responder) InternalServerError

func (r *Responder) InternalServerError(w http.ResponseWriter)

func (*Responder) JSON

func (r *Responder) JSON(w http.ResponseWriter, statusCode int, i any)

func (*Responder) NoContent

func (r *Responder) NoContent(w http.ResponseWriter)

func (*Responder) OK

func (r *Responder) OK(w http.ResponseWriter, i any)

func (*Responder) Redirect

func (r *Responder) Redirect(w http.ResponseWriter, code int, url string)

type ResponderOption

type ResponderOption func(r *Responder)

func WithErrConverter

func WithErrConverter(errConverter ErrConverter) ResponderOption

func WithLogger

func WithLogger(log *slog.Logger) ResponderOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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