@cerbos/http
v0.26.0
Published
Client library for interacting with the Cerbos policy decision point service over HTTP from browser-based applications
Downloads
66,309
Readme
@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, you'll need to apply a polyfill.
You can use it in server-side Node.js applications, but the gRPC client might be more appropriate.
Prerequisites
- Cerbos 0.16+
- Node.js 20+
fetch
Installation
$ npm install @cerbos/httpExample usage
import { HTTP } from "@cerbos/http";
const cerbos = new HTTP("http://localhost:3592");
await cerbos.isAllowed({
principal: {
id: "[email protected]",
roles: ["USER"],
attr: { tier: "PREMIUM" },
},
resource: {
kind: "document",
id: "1",
attr: { owner: "[email protected]" },
},
action: "view",
}); // => trueFor more details, see the HTTP class documentation.
CommonJS support
This package is ESM-only, but may be required from CommonJS modules in Node.js versions 20.19.5+, 22.15+, and 24+.
