Rests is a JavaScript/TypeScript library designed to streamline and centralize HTTP API requests by enabling the generation of a structured API client SDK. It empowers developers to define API endpoints, methods, and parameters in a declarative, JSON-like configuration, thereby establishing a single source of truth for all API interactions. Key features include a robust configuration system that facilitates advanced handling of validation, authentication, and request/response hooks, alongside a powerful mechanism for complex inheritance that allows for the categorization of requests to prevent repetition. A significant differentiator is its capability to automatically generate TypeScript types for the defined API, enhancing developer experience and ensuring type safety. Additionally, it supports schema definition from pure JSON and can generate basic markdown API references. Rests offers universal compatibility, functioning seamlessly across both browser and Node.js environments. The current stable version is 1.1.1. While a specific release cadence is not explicitly detailed, the project appears to be under active development, evidenced by mentions of a 'Private edition' offering expanded functionalities. Its primary distinction lies in transforming a simple, declarative API definition into a fully-fledged, strongly-typed, and object-oriented API client, significantly simplifying network communication compared to direct `fetch` or `axios` implementations.
npm install restsVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to define an API schema using the `Rests` factory, initialize the client, make successful and error-prone API calls, handle custom parameter validation, and set category-specific options like authorization.
Change `const Rests = require('rests');` to `const Rests = require('rests').default;`Review the official Rests documentation to understand the feature set available in the public npm package. Contact the Rests maintainers for details regarding the 'Private edition' if those features are required.
Install the package globally using `npm i rests -g` if you intend to use its CLI directly, or execute CLI commands via `npx rests <command>`.
Ensure you are importing the default export: `const Rests = require('rests').default;`Ensure all required parameters meet the specified validation and formatting rules before making the API call. Refer to the API schema definition for the specific endpoint.
Verify that `const API = Rests({...});` has been executed and the `API` object is properly exported from its definition file and imported where it's being used.Implement proper error handling with a `.catch()` block on your API calls. Inspect `err.statusCode`, `err.json`, or `err.message` for details. Ensure authentication tokens are correctly set, potentially through category `$options` or when initializing a specific API category.
No dependency data recorded yet.