A set of Examples on how to call the OpenFGA JS SDK
Example 1: A bare-bones example. It creates a store and runs a set of calls against it including creating a model, writing tuples, and checking for access.
OpenTelemetry: An example that demonstrates how to integrate the OpenFGA JS SDK with OpenTelemetry.
API Executor:
Demonstrates how to use the low-level executeApiRequest and executeStreamedApiRequest methods to call OpenFGA endpoints directly — both standard request/response and streaming. Useful when calling new, experimental, or custom endpoints not yet wrapped by the SDK.
Prerequisites:
dockermakeNode.js16.13.0+
Steps
- Clone/Copy the example folder
- If you have an OpenFGA server running, you can use it, otherwise run
make run-openfgato spin up an instance (you'll need to switch to a different terminal after - don't forget to close it when done) - Run
make setupto install dependencies - Run
make runto run the example
Steps
- Build the SDK
- In the Example
package.jsonchange the@openfga/sdkdependency from a semver range like below
"dependencies": {
"@openfga/sdk": "^0.9.4"
}to a file: reference like below
"dependencies": {
"@openfga/sdk": "file:../../"
}- If you have an OpenFGA server running, you can use it, otherwise run
make run-openfgato spin up an instance (you'll need to switch to a different terminal after - don't forget to close it when done) - Run
make setupto install dependencies - Run
make runto run the example