A Node.js package for making HTTP requests with ease. It provides a simple interface to define and execute requests, along with options for customization.
Installation
Usage
Options
define
Takes in an input of type string | Request | URL and an options object.
The define method is used to define a request with the following options:
method: The HTTP method (default is "POST").
input: The input schema for the request payload.
output: The output schema for the response payload.
headers: Additional headers for the request.
Error Handling
The zap package uses the fetch API under the hood. It will throw an error if the request fails. You can use a try/catch block to handle errors.
The following errors are thrown by the handler if the request fails:
HTTPError: If the response status code is not ok.
TimeoutError: If the request times out.
ZodError: If the response payload does not match the output schema.
Will not throw zod error if output is not defined.
API
RestMethods
An object containing various HTTP methods for requests.
Zap Class
The main class that provides the core functionality for making HTTP requests. It includes methods for defining and executing requests.
Callback Function
When defining a request, you will receive a callback function that takes an input object and returns a Promise of the response payload.
This input will be parsed to query parameters for GET requests and as the request payload for other methods.