Documentation
¶
Overview ¶
Package httpresponse owns common HTTP JSON response framing for API servers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WriteJSON ¶
func WriteJSON(writer http.ResponseWriter, status int, value any)
WriteJSON writes the supplied status and standard JSON body. As at the existing HTTP boundaries, headers are committed before encoding and an encoding/write failure does not attempt a second response.
func WriteLocalizedRejection ¶
func WriteLocalizedRejection(w http.ResponseWriter, r *http.Request, manager *localization.Manager, message localization.Message, status int, envelope RejectionEnvelope)
WriteLocalizedRejection writes an already-decided rejection. Validation and authentication remain with the calling middleware. JSONErrorText retains the auth boundary's JSON text passed through http.Error, including its newline, content type and nosniff behavior; it is not a normal JSON response.
func WritePropertyJSON ¶
func WritePropertyJSON(writer http.ResponseWriter, status int, value any)
WritePropertyJSON binds the property-number domain before the shared HTTP response owner writes headers and standard JSON. It adds no response framing or error policy of its own.
Types ¶
type RejectionEnvelope ¶
type RejectionEnvelope uint8
RejectionEnvelope selects the existing text/plain rejection body format.
const ( PlainText RejectionEnvelope = iota JSONErrorText )