UNPKG

@opra/client

Version:

Opra Client package

80 lines (56 loc) โ€ข 2.37 kB
<div align="center"> <a href="https://oprajs.com"> <img src="https://oprajs.com/img/opra-header-block.webp" width="880" alt="OPRA โ€” Open Platform for Rich APIs" /> </a> # @opra/client Type-safe HTTP client for the OPRA framework [![NPM Version][npm-image]][npm-url] [![NPM Downloads][downloads-image]][downloads-url] [![CI Tests][ci-test-image]][ci-test-url] [![Test Coverage][coveralls-image]][coveralls-url] [๐ŸŒ Documentation](https://oprajs.com) ยท [๐Ÿš€ Getting Started](https://oprajs.com/docs/introduction) ยท [๐Ÿ“ฆ Packages](https://github.com/panates/opra#packages) ยท [๐Ÿ’ฌ Issues](https://github.com/panates/opra/issues) </div> --- Type-safe HTTP client for the [OPRA](https://oprajs.com) framework. Built from your API document โ€” no manual client code required. ## Features - **`OpraHttpClient`** โ€” Ready-to-use HTTP client backed by the Fetch API - **`HttpClientBase`** โ€” Extensible base class for custom client implementations - **`FetchBackend`** โ€” Configurable fetch backend with default headers and options - **Interceptors** โ€” Request/response middleware pipeline - **Type-safe requests** โ€” All calls are typed from the server API document ## Installation ```bash npm install @opra/client ``` ## Usage ```typescript import { OpraHttpClient } from '@opra/client'; const client = new OpraHttpClient('https://api.example.com', { document: apiDocument, }); const body = await client.request('users/findMany').getBody(); ``` ### With interceptors ```typescript const client = new OpraHttpClient(baseUrl, { document: apiDocument, interceptors: [ async (req, next) => { req.headers.set('Authorization', `Bearer ${token}`); return next(req); }, ], }); ``` ## Node Compatibility - node >= 20.x ## License Available under [MIT](LICENSE) license. [npm-image]: https://img.shields.io/npm/v/@opra/client [npm-url]: https://npmjs.org/package/@opra/client [downloads-image]: https://img.shields.io/npm/dm/@opra/client.svg [downloads-url]: https://npmjs.org/package/@opra/client [ci-test-image]: https://github.com/panates/opra/actions/workflows/test.yml/badge.svg [ci-test-url]: https://github.com/panates/opra/actions/workflows/test.yml [coveralls-image]: https://coveralls.io/repos/github/panates/opra/badge.svg?branch=main [coveralls-url]: https://coveralls.io/github/panates/opra?branch=main