API - POST
Entities in nodb are JSON objects with arbitrary constructs. They can have nested hierarchy.
To nest your entities you must make separate calls to each sub-entity's named route.
Upon creation each entity will have auto generated id
. This will be its identifier for your restful API.
Creating entities
To create an entity simply make a signed POST request to your named route:
curl -X POST https://api.nodb.sh/{app-name}/{env}/named-route?token={token} \
-d '[{ "foo": "bar" }]'
POST body must be an array.
You can use POST request to store multiple items in a single call.
This POST request will create your first route called 'named-route'. It can be anything. Say, 'books' or 'planets'.
After this following route will be accessible for fetch (GET):
curl https://api.nodb.sh/{app-name}/{env}/named-route?token={token}
This will return your foo-bar entity with enriched meta data contained within __meta
object.
{
"entities": [
{
"id": "6gaaszin",
"foo": "bar"
"__meta": {
"self": "/{app-name}/{env}/named-route/6gaaszin",
"subtypes": {}
}
}
]
}
Creating sub-entities
Sub-entities define nested structure of your API. They are formed following the familiar restful concept of separating models with their ID's.
/model1/:id1/model2/:id2/...
Maximum number of nested levels is 4.
To create a sub-entity just follow the same principle of calling named routes. In this case you need 'id' of your entity to which you're creating a sub-entity. In this case let's call them 'level2':
curl -X POST https://api.nodb.sh/{app-name}/{env}/named-route/6gaaszin/level2?token={token} \
-d '[{ "abc": 123 }]'
To create another level add it to /level2/:id/another-level
, etc.
As mentioned above, maximum number of levels after the root entity is 4.