@cerbos/http
Version:
Client library for interacting with the Cerbos policy decision point service over HTTP from browser-based applications
61 lines (41 loc) • 1.65 kB
Markdown
# @cerbos/http
[](https://www.npmjs.com/package/@cerbos/http)
Client library for interacting with the Cerbos policy decision point service over HTTP.
This is primarily intended for use in browsers, and requires `fetch` to be available globally.
If you're targeting [old browsers](https://caniuse.com/fetch), you'll need to apply [a polyfill](https://www.npmjs.com/package/whatwg-fetch).
You can use it in server-side Node.js applications, but the [gRPC client](../grpc/README.md) might be more appropriate.
## Prerequisites
- Cerbos 0.16+
- Node.js 20+
- `fetch`
## Installation
```console
$ npm install @cerbos/http
```
## Example usage
```typescript
import { HTTP } from "@cerbos/http";
const cerbos = new HTTP("http://localhost:3592");
await cerbos.isAllowed({
principal: {
id: "user@example.com",
roles: ["USER"],
attr: { tier: "PREMIUM" },
},
resource: {
kind: "document",
id: "1",
attr: { owner: "user@example.com" },
},
action: "view",
}); // => true
```
For more details, [see the `HTTP` class documentation](https://cerbos.github.io/cerbos-sdk-javascript/classes/_cerbos_http.HTTP.html).
## CommonJS support
This package is ESM-only, but may be `require`d from CommonJS modules in Node.js versions 20.19.5+, 22.15+, and 24+.
## Further reading
- [API reference](https://cerbos.github.io/cerbos-sdk-javascript/modules/_cerbos_http.html)
- [Cerbos documentation](https://docs.cerbos.dev)
## Get help
- [Join the Cerbos community on Slack](https://go.cerbos.io/slack)
- [Email us at help@cerbos.dev](mailto:help@cerbos.dev)