APIProvider.renderURL()method
Render the full final URL for an API request to a given endpoint with a given payload.
renderURL(endpoint: Endpoint<PP, RR>, payload: PP, caller?: AnyCaller): URL
new APIProvider<P, R>()
| Return | |
|---|---|
APIProvider<P, R> | Abstract base for API providers that send requests to a set of Endpoint definitions rooted at a common base URL. |
| Property | Type | |
|---|---|---|
.url | URL | The common base URL that every endpoint request is resolved against. required readonly |
Abstract base for API providers that send requests to a set of Endpoint definitions rooted at a common base URL.
renderURL(), createRequest(), fetch(), and parseResponse(); call() orchestrates them.AsyncDisposable so providers can be wrapped and disposed in a chain.The abstract base class every API provider implements. APIProvider<P, R> defines the surface that endpoint calls go through: call(endpoint, payload) to execute a typed endpoint, and fetch(request) as the lower-level transport step that wrapper providers intercept.
You never instantiate APIProvider directly — use the concrete ClientAPIProvider (or a mock), optionally wrapped in ThroughAPIProvider subclasses. APIProvider implements AsyncDisposable.
Code that accepts "any provider" should type against APIProvider so a bare client, a validated chain, or a mock are all interchangeable:
import type { APIProvider } from "shelving/api"
async function loadUser(provider: APIProvider, id: string) {
return provider.call(getUser, { id }); // works with any provider in the chain
}const provider = new ClientAPIProvider({ url: "https://api.example.com" });
const user = await provider.call(getUser, { id: "abc" });Render the full final URL for an API request to a given endpoint with a given payload.
renderURL(endpoint: Endpoint<PP, RR>, payload: PP, caller?: AnyCaller): URL
Create a Request that targets this endpoint with a given base URL.
createRequest(endpoint: Endpoint<PP, RR>, payload: PP, options?: RequestOptions, caller?: AnyCaller): Request
Send a Request and return its Response (defaults to the JavaScript fetch() API).
fetch(request: Request): Promise<Response>
Parse an HTTP Response for this endpoint into a result value.
parseResponse(_endpoint: Endpoint<PP, RR>, response: Response, caller?: AnyCaller): Promise<RR>
Send a payload to an Endpoint and retrieve the parsed result.
call(endpoint: Endpoint<PP, RR>, payload: PP, options?: RequestOptions, caller?: AnyCaller): Promise<RR>