Fetch function signature.
Fetch middleware.
Creates a fetch client from a chain of middlewares.
Retrieves the method of a request.
Retrieves the target URI of a request.
Retrieves the header fields of a request.
Parses a numeric field value.
Parses a date field value.
Parses a duration field value.
Parses a value stated as a quoted string.
Parses a list field value.
Parses a name / value pair.
Parses an item field value.
The initial part of the request was received and not yet rejected.
The server is switching to the protocol requested through the Upgrade header field.
The server is likely to send a final response including the header fields of this informational response.
The request succeeded.
The request was fulfilled and one or more new resources were created.
The request was accepted for processing, which hasn't completed.
The request succeeded, but a transforming proxy modified the enclosed content.
The request was fulfilled and there is no additional content to send.
The request was fulfilled and the user agent is expected to reset the document view that sent it.
The range request was fulfilled by transferring one or more parts of the selected representation.
The target resource has more than one representation, with information about the alternatives provided for selection.
The target resource was assigned a new permanent URI, to be used by future references.
The target resource resides temporarily under a different URI.
The user agent is redirected to a different resource, as an indirect response to the original request.
The condition of a conditional GET or HEAD request evaluated to false, leaving the cached response current.
The target resource is to be accessed through a proxy.
The target resource resides temporarily under a different URI, to be requested with the same method.
The target resource was assigned a new permanent URI, to be requested with the same method.
The request won't be processed, as it is perceived to be a client error.
The request lacks valid authentication credentials for the target resource.
Reserved for future use.
The server understood the request but refuses to fulfil it.
The origin server found no current representation for the target resource, or won't disclose that one exists.
The request method is known by the origin server but not supported by the target resource.
No response matching the proactive content negotiation header fields of the request can be produced.
The client needs to authenticate with a proxy.
No complete request message was received within the time the server was prepared to wait.
The request conflicts with the current state of the target resource.
Access to the target resource is no longer available at the origin server, likely permanently.
The request is refused without a defined Content-Length header field.
One or more conditions given in the request header fields evaluated to false.
The request content is larger than the server is willing or able to process.
The target URI is longer than the server is willing to interpret.
The request content is in a format unsupported by this method on the target resource.
The ranges in the Range header field were rejected, none of them being satisfiable for the selected
representation or too many having been requested.
The expectation given in the Expect header field couldn't be met.
The request was directed at a server unable or unwilling to answer authoritatively for the target URI.
The request content was syntactically correct, but its instructions couldn't be processed.
The request is refused under the current protocol, but might be served after an upgrade.
The origin server requires the request to be conditional.
The client sent too many requests within a given amount of time.
The request is refused because its header fields are too large.
Access to the resource is denied as a consequence of a legal demand.
The server met an unexpected condition preventing it from fulfilling the request.
The server doesn't support the functionality required to fulfil the request.
The server, acting as a gateway or proxy, received an invalid response from an inbound server.
The server is temporarily unable to handle the request, for instance under overload or scheduled maintenance.
The server, acting as a gateway or proxy, received no timely response from an upstream server.
The server doesn't support, or refuses to support, the major HTTP version of the request.
The client needs to authenticate to gain network access.
Client assembly and HTTP utilities.
Provides a composable middleware layer over the standard
fetchfunction, with ready-made middlewares for recurring concerns published as subpath modules. A Middleware wraps a Fetch implementation, returning a drop-in replacement that adjusts requests and responses as they flow through, and createFetch assembles a chain of them into a single client to be shared across an application.Named constants for the HTTP status codes are provided alongside, so that response handling reads as intent rather than as bare numeric literals. Coverage is complete for the codes defined by RFC 9110 § 15, extended with the registered codes in common use defined by later specifications; placeholders reserved without a name and codes registered by narrower protocol extensions are left out and compared as plain numbers.
Parsing helpers turn the textual field values HTTP exchanges are made of into plain JavaScript ones, sparing each call site the splitting, unquoting and date conversion the field grammars call for. Malformed input is reported as stated or as missing, never as an error, so the consumer decides how to handle whatever a peer got wrong.
Usage
A named constant stands in for the status code it names:
A middleware of your own is written as a function wrapping the client it delegates to:
A client is assembled once from the middlewares an application needs and shared wherever an exchange is performed:
The request accessors report what an exchange states, wherever it is stated, so that a bare target, a
Requestand a target paired with options are all read alike:Numbers, dates and durations are reported as plain numbers and milliseconds:
Structured values are taken apart along the separators their field grammar uses, one helper per separator: quotes protect whatever they enclose, a comma splits a list into elements, an equals sign splits a parameter into a name and a value, and a semicolon splits an item into a value and the parameters qualifying it:
Composing them reads a field with more structure, and equally one whose grammar this package doesn't cover, with a parser of your own in place of the second step:
See