Overview
The store services allow you to store object in a NoSQL database it handles for you mapping between objects, have a security policy and check the object with JSON Schema
We have currently File, DynamoDB and MongoDB storage
Expose REST API
Inside the configuration you can add a block for expose the store as a REST API
{
...
"expose": {
"url": "/storeurl", // By default the URL is the store name in lower case
"restrict": {
"update": true, // Prevent the creation of an object the PUT method wont be exposed
"delete": false // Allow delete for the object
}
}
...
}
The above configuration will end up creating the following routes:
POST /storeurl
GET /storeurl/[uuid]
DELETE /storeurl/[uuid]
You can see that by default, once the store exposed all the methods are available unless you restrict them.
Configuring Mapping
As an example we will use the Users / Idents stores used by the Authentication module.
A User has several Idents so in NoSQL we need to deduplicate a part of the Ident object inside an array inside the User object
The following is the Idents store configuration
{
...
"map": {
"Users": { // Target store
"key": "user", // Property inside Ident Object
"target": "idents", // Property on the User Object
"fields": "type", // Fields from the Ident Object ( uuid is added by default )
"cascade": true // If User object is delete then delete all the linked Idents
}
}
So if you have a user like
{
...
"uuid": "user_01"
}
Then you save a new Ident object like
{
...
"uuid": "ident_01",
"user": "user_01",
"type": "Google"
}
Once the Ident saved, the User object will look like
{
...
"uuid": "user_01",
"idents": [{"uuid":"ident_01","type":"Google"}]
...
}
Then if you update the field type on your Ident object the User object will reflect the change, as well as if you delete the ident object it will be removed from the User object.
If cascade = true, then if you delete the User object, all attached Idents will be delete aswell.