@cerbos/http
TypeScript icon, indicating that this package has built-in type declarations

0.19.2 • Public • Published

@cerbos/http

npm

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 18+
  • fetch

Installation

$ npm install @cerbos/http

Example usage

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.

Further reading

Get help

Package Sidebar

Install

npm i @cerbos/http

Weekly Downloads

8,532

Version

0.19.2

License

Apache-2.0

Unpacked Size

1.05 MB

Total Files

128

Last publish

Collaborators

  • ahaines
  • alexolivier
  • cerbosdev