Using headers
HTTP headers are key-value pairs that contain additional information about a request or a response. They are commonly used to pass metadata, such as a content type, authentication tokens, or caching directives.
Using search params (query)
URL search parameters, also known as query parameters, are a way to provide additional information to a request. They are encoded in the query string of a URL in key-value pairs. Search params are typically used in GET requests to filter, sort, or paginate data.
Using path params
Path parameters are a way to include dynamic values in the URL path of a request. They are typically used to identify a resource being accessed or modified. For example, in the URL /users/userId represents a path parameter that can be replaced with a specific user identifier when making a request.
Using bodies
Bodies are used to send data in a request and receive data in a response. Request bodies are commonly used to include a payload of data that the server will process, whereas response bodies may contain the result returned by the server. A body can contain various types of data, such as JSON, XML, and binary data such as images and files.
Authentication
Authentication is a process of verifying the identity of a user or system. When using a web API, authentication is often required to ensure that only authorized users can access certain resources or perform specific actions.
Handling errors
@zimic/fetch fully types the requests and responses based on your schema. If a response fails with a status code in the 4XX or 5XX ranges, the response.ok property will be false.
Testing
Testing is an important part of most software development processes. When using @zimic/fetch, there are two general strategies to test your code.
Typegen
@zimic/fetch uses @zimic/http, which can infer types from OpenAPI documentation and generate ready-to-use schemas to type your @zimic/fetch clients.