Create a Store
A store is a OpenFGA entity that contains your authorization data. You will need to create a store in OpenFGA before adding an authorization model and relationship tuples to it.
This article explains how to setup an OpenFGA store.
Step By Step
- Node.js
- Go
- .NET
- Python
- curl
const { OpenFgaApi } = require('@openfga/sdk'); // OR import { OpenFgaApi } from '@openfga/sdk';
const openFga = new OpenFgaApi({
apiScheme: process.env.FGA_API_SCHEME, // optional, defaults to "https"
apiHost: process.env.FGA_API_HOST // required, define without the scheme (e.g. api.openfga.example instead of https://api.openfga.example)
});
const { id: storeId } = await openFga.createStore({
name: "FGA Demo Store",
});
import (
openfga "github.com/openfga/go-sdk"
"os"
)
func main() {
configuration, err := openfga.NewConfiguration(openfga.Configuration{
ApiScheme: os.Getenv("FGA_API_SCHEME"), // optional, defaults to "https"
ApiHost: os.Getenv("FGA_API_HOST"), // required, define without the scheme (e.g. api.openfga.example instead of https://api.openfga.example)
})
if err != nil {
// .. Handle error
}
apiClient := openfga.NewAPIClient(configuration)
resp, _, err := apiClient.OpenFgaApi.CreateStore(context.Background()).Body(openfga.CreateStoreRequest{
Name: openfga.PtrString("FGA Demo Store"),
}).Execute()
if err != nil {
// .. Handle error
}
}
using OpenFga.Sdk.Api;
using OpenFga.Sdk.Configuration;
using Environment = System.Environment;
namespace ExampleApp;
class MyProgram {
static async Task Main() {
var configuration = new Configuration() {
ApiScheme = Environment.GetEnvironmentVariable("FGA_API_SCHEME"), // optional, defaults to "https"
ApiHost = Environment.GetEnvironmentVariable("FGA_API_HOST") // required, define without the scheme (e.g. api.openfga.example instead of https://api.openfga.example)
};
var fgaClient = new OpenFgaApi(configuration);
var store = await fgaClient.CreateStore(new OpenFga.Sdk.Model.CreateStoreRequest()
{
Name = "FGA Demo Store"
});
}
}
import os
import openfga_sdk
from openfga_sdk.api import open_fga_api
from openfga_sdk.models.create_store_request import CreateStoreRequest
configuration = openfga_sdk.Configuration(
scheme = os.environ.get('FGA_API_SCHEME')
api_host = os.environ.get('FGA_API_HOST'),
)
# Create an instance of the API class
fga_client_instance = open_fga_api.OpenFgaApi(openfga_sdk.ApiClient(configuration))
async def create_store():
try:
# Create a store
body = CreateStoreRequest(
name = "FGA Demo",
)
api_response = await fga_client_instance.create_store(body)
except openfga_sdk.ApiException as e:
print("Exception when calling OpenFgaApi->create_store: %s\n" % e)
curl -X POST $FGA_API_HOST/stores \
-H "content-type: application/json" \
-d '{"name": "FGA Demo Store"}'