get-it is a generic HTTP request library designed for both Node.js (>=14.0.0) and modern browsers, including web workers. Currently at stable version 8.7.2, the package maintains an active development pace with frequent bug fixes and minor feature releases within its v8.x series. Its key differentiator is a highly modular, middleware-based architecture, drawing inspiration from `http-client`. This approach enables developers to compose specific functionalities such as Promise or Observable patterns, automatic request retries, cancellation, JSON serialization/deserialization, GZIP unwrapping (Node.js), base URL prepending, redirect following, and detailed upload/download progress events. The modularity aims to provide a small browser bundle footprint while offering extensive and configurable HTTP client features. It transparently handles various request body types depending on the execution environment and provides options for network timeouts.
npm install get-itVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to configure and use `get-it` with common middleware for making asynchronous HTTP requests using Promises, including setting a base URL, parsing JSON responses, and handling basic GET/POST operations and errors.
Upgrade your Node.js environment to version 14.0.0 or higher. Consider using `nvm` to manage multiple Node.js versions.
Ensure `promise()` middleware is included in your `getIt` configuration: `getIt([/* other middleware */, promise()])` or `request.use(promise())`.
Be mindful of the execution environment when developing universal code. Implement conditional logic or abstraction layers if these differences are critical to your application's behavior.
Always include `jsonResponse()` middleware if you expect to receive and automatically parse JSON responses. Conversely, omit it if you need the raw string body.
Add `promise()` to your middleware chain: `const request = getIt([..., promise()]);`
Verify the server is sending valid JSON and setting the `Content-Type` header correctly (e.g., `application/json`). If the response is not JSON, remove `jsonResponse()` middleware or add custom parsing logic.
Use ESM `import` statements: `import { getIt } from 'get-it';` and `import { ... } from 'get-it/middleware';`. Ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json` or using `.mjs` extensions).Increase the `timeout` values in the `timeout` middleware (e.g., `{ connect: 10000, socket: 30000 }`). Verify network connectivity to the target server.