CRUDs created in the Console are handled and exposed to the services within your project by the Crud Service
In order to create a new CRUD, open the dedicated section, select Create new CRUD and fill in the following information:
- Name: the name of the CRUD that will be used for data storage (we recommend using
snake-caseas naming convention). In our case, we will name the collection “books”;
- Internal endpoint: this is the first endpoint that will be exposed by the Crud Service. The console will prefill it but you can change it according to your preference.
Once you have entered all required fields, press the Create button on the right and you will see your newly created CRUD.
As soon as you push Create a new page, "books" in our example, is created and you can enter a short and optional description of your collection: default description will be “Collection of books”.
In the section Fields, you can enter the properties of your collection.
By default, there are fields that can not be changed, such as:
You can add new fields by selecting Add new and fill in the blank form with the value you need.
You can add the fields you need and select the appropriate properties:
- name (we recommend using
camelCasenaming convention); in our case we will insert "title", "author", "year", "new", etc.
- string if it is a classic text string
- number if it is a number
- date if it is a date. The date it must be a string compliant with ISO-8601 standard with the following format: YYYY-MM-DDTHH:mm:ss.sssZ
- boolean if it can only be
- Geopoint if you want to save a specific place coordinates
- Array if you want to save as an ordered set of properties
- Object if you want to insert an object.
- If you select required the property is mandatory.
- If you select nullable you can make the value null.
- In the description field you can enter a short optional description.
The Crud Service will handle your data model and expose its API to the services within your project, without the need to expose the CRUD to the outside world, by using the specified CRUD endpoint routes in the dedicated card in CRUD detail view.
If you want the CRUD to be accessible from the outside, you can create a new CRUD-type Endpoint in the Design Endpoint section.
Beyond the first route, automatically exposed when creating the CRUD, you can always add new routes and modify existing ones. When viewing CRUD detail information you can view all the internal routes associated with your CRUD and edit them. In our case we will see the first internal endpoint with a routh base path equal to "/books". The default state (used on document creation) is set to DRAFT by default.
To create a new endpoint click on the
Add new button in the card and fill in Route base path and the Default state property for the new endpoint.
Please note that these endpoint must be unique through all the configured CRUD, the Console will check for you that this constraint is satisfied when creating or editing any CRUD route in your project. In case this happens you will be warned with an error message.
You can always change the default state of an existing route by simply clicking on the field default state. The two possible values are DRAFT or PUBLIC.
You can delete a route but you must always leave at least one endpoint exposed by the Crud Service, otherwise the CRUD won't be accessible by anyone, neither your services in your project.
If you want, you can upload your fields from file, selecting Import fields from File. Remember that the file must be a JSON with the following directions:
- Enter the property
- Add properties with their
typesspelling as follow:
Array_RawObject support both a custom JSON Schema.
It can be used to specify the schema of the object for the former and the schema of each item of the array for the latter.
To do it, add a property schema to the field.
The following options are supported:
properties: must be a valid 'properties' field of a json schema of type object.
required: array of name properties that are required. It's the required field of a JSON schema of type object.
trueif the object can have additional properties.
This is an example of a field of type
RawObject where is specified the schema object the properties of the object (properties), the required properties (
somethingNumber) and if object could accept additional properties (in this example it is set to false):
The following is an example of
Array_RawObject (Array of RawObject) with the JSON schema of the object items.
Here, schema refers to the object of each item (which are of type
RawObject). It's NOT the schema of the array itself.
So, each item of the array must follows the following rules:
- name property must be a string ad it is required
- neastedArr property must be an array of numbers
- can have additional properties
The schema specified in properties (for both of them) cannot have the following operators:
Here's an example of the file to upload.
Once you imported the JSON from files, it automatically appears in the table under the default fields.
If you want to delete a row, select red trash symbol on the right of the the table.
The collection has not yet been saved it is necessary to continue the process described below
You can configure the indexes, a data structure designed to improve search (query) data.
After selecting a CRUD, to create a new index select create new in the "Indexes" section. Once you named the index you need to choose among: geo, hash or TTL. Then, you can choose whether to make the index unique by ticking "unique".
To take in deeper how to use API exposed by the CRUD Service check out the CRUD Endpoints Documentation.