Reference
@muze-nl/metro-core reference
client(...options)
Creates a Client. Options are applied in order. A string, URL, or Location sets or updates the base URL. A function is added as middleware. A plain object can contain Fetch Request options, url, middlewares, verbs, or trace options.
new Client(...options)
The class behind client(). It is exported for extension, but application code normally uses client().
Client methods
The default verb methods are get, post, put, delete, patch, head, options, and query. You can replace the list with client({ verbs: ['get', 'post'] }); each name becomes a method and the HTTP method is the upper-case name.
client.with(...options)
Returns a new Client with more default options or middleware. The original client is not changed.
Middleware signature
req is a Metro request, next(req) calls the next middleware or fetch(), and context contains { client, options, trace, fetch }. Use context.fetch(req) for nested Metro calls that keep the trace context.
request(...options)
Creates a Fetch-compatible Request proxy. Strings and URLs update the URL, URLSearchParams append query values, body-compatible values become the body, and plain objects can contain Fetch request options.
Metro request additions:
with() returns a derived request. data exposes the original body value passed to Metro before Fetch turns it into a stream.
response(...options)
Creates a Fetch-compatible Response proxy. String and body-compatible values become the body. Plain objects can contain status, statusText, headers, body, url, type, and redirected.
with() returns a derived response. data exposes the original body value passed to Metro.
url(...options)
Creates a frozen URL proxy with a .with() helper. Strings are resolved relative to the current URL. URLSearchParams and searchParams append query parameters; search replaces them.
Accepted object keys include hash, fragment, host, hostname, href, password, pathname, port, protocol, username, search, searchParams, and hashParams.
metroError(message, ...details)
Logs the message with Metro’s console prefix and returns an Error object. Metro uses this for its own configuration errors.
deepClone(value)
Copies arrays and plain objects. Custom classes and functions are preserved by reference.