httpx

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 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.

Documentation

Overview

Package httpx holds the HTTP helpers the handlers share: the JSON and error writers and the query parsers.

Index

Constants

This section is empty.

Variables

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

ErrBodyTooLarge is returned for a body over the handler's limit.

Functions

func QueryInt

func QueryInt(r *http.Request, key string, def int) int

QueryInt reads an integer query parameter; empty or unparseable falls back to def.

func ReadJSON

func ReadJSON(r *http.Request, dst any) error

ReadJSON decodes a JSON request body into dst. An empty or malformed body is a 422 StatusError, an oversized one a 413.

func StatusCodeOf

func StatusCodeOf(err error) (int, bool)

StatusCodeOf returns the status an error carries, when it carries one.

func WriteError

func WriteError(w http.ResponseWriter, status int, detail string)

WriteError writes the error body {"detail": ...} with the status.

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, v any)

WriteJSON serialises v as JSON with the given status.

Types

type StatusError

type StatusError struct {
	Code    int
	Message string
	// contains filtered or unexported fields
}

StatusError is an error that carries its HTTP status and, when it stands for a sentinel, unwraps to it.

func (*StatusError) Error

func (e *StatusError) Error() string

func (*StatusError) Unwrap

func (e *StatusError) Unwrap() error

Unwrap returns the sentinel the error stands for, when there is one.

Jump to

Keyboard shortcuts

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