Purest is a flexible JavaScript library for constructing expressive REST API clients, abstracting away the low-level HTTP request details. It enables developers to define detailed API configurations, including base URLs, paths, headers, and versioning, for various service providers. The library then facilitates interaction through a fluent, chainable API that supports custom query parameters, authentication, and HTTP methods, with options for preconfigured defaults and method aliases. Currently in stable version 4.0.3, Purest is actively maintained, supporting Node.js environments (>=12.0.0) and ships with TypeScript types for improved developer experience. It relies on the `request-compose` library for its underlying HTTP capabilities. Purest differentiates itself by providing a highly configurable and declarative approach to API consumption, allowing for complex API structures to be represented and interacted with in an abstract yet powerful manner, making it suitable for managing interactions with multiple, diverse REST APIs within a single application.
npm install purestVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to configure a Purest client for Google's YouTube API, apply an authentication token, query for channels by username, and execute the request.
Always consult the official migration guides provided in the GitHub repository or npm documentation when upgrading Purest across major versions to understand necessary configuration and code changes.
Ensure all Purest method chains are terminated with a call to `.request()` (e.g., `purestClient.get('path').auth(token).request()`) to execute the API call.Carefully verify the structure and token placement within your `config` object for each provider. Ensure that `auth()` calls match the `{auth}` token in your headers configuration, and `{path}` and `{version}` tokens are correctly used in URL paths.Always use the default import syntax: `import purest from 'purest';` for ESM, or `const purest = require('purest');` for CommonJS.Change your import statement from `import { purest } from 'purest';` to `import purest from 'purest';`.Verify that your `purest({provider: 'your-provider', config})` call is correctly configured and successfully returns a client object before attempting to chain methods or call `.request()`.Ensure your `config` object includes a correctly structured entry for the provider name you are trying to initialize (e.g., `config = { 'google': { ... } }`).