I have been trying out several open source headless CMS projects including Gentics Mesh. Gentics Mesh is an interesting tool but I had difficulties understanding its database. I wanted simpler database structure as I had an existing database that I wanted to control with the tool. So far, with its simplicity, flexibility, and powerfulness Directus is the most impressive one.
If you need to deal with RDBMS backend with CRUD APIs, then Directus can help you a lot of time!
Directus is easy to configure with existing relational database, or create new tables ( collections ) from within Directus. If you have an existing database on PostgreSQL or mysql / mariadb, then all you have to do is to install Directus and configure database to the existing one – Directus will generate its own tables there and other existing tables can be configured in Web interface. If you do not have database yet, then create one and install Directus, then create tables (Directus calls them “collections”) from Directus. The latter is preferable and easier to manage of course though.
In my case, I created new database and tables with SQL script, providing some specific fields (id for PK, date_created, data_updated, etc… for Directus to control automatically.)
Once configured with your tables (collections), REST APIs are there for you automatically.
Collections can be individually access-controlled. Some collections can be public to everybody (without logging in), while others can be restricted to specific users. CRUD control is also configurable.
Adding public “read” access to “Child” collection enables anyone to see the data.
Retrieving specific fields of collection (table)
You can specify fields to retrieve. Just add URL parameter like “?fields=field1,field2,field3…” at the end of your request URL. The parameter can be even more flexible as to let you specify related tables and their fields as well. (Asterisk can be used to specify “all”.)
GET name, age of parent and age of children
Access to https://directus.your-domain.com/items/parent?fields=name,age,children.age
Relations can be configured so that REST API can manipulate child collections as well from parent collection. Say, you have a Parent table, with One-to-Many relation of Children table, then configuring O2M relation from Parent to Children can enable Parent REST API call to control Children as well. (e.g., “?fields=*.*” can mean “include all the child collections”, “?fields=parent.*,child.a, child.b” can mean “all the parent fields and child’s field a and b only.” Of course POST and PATCH can work with child collections as well!)
Configuring One-to-Many relation from “Parent” to “Child” object
- Authentication via API returns JWT tokens, which is useful for UI based applications. And administrators can assign a static token to users as well, which can be used as API KEY and useful for no-UI based applications.
Given a proper access control, REST API is available for access with no coding at all!
Some other features
There are more to be found including:
- Files like image files can be handled using “files” or “assets” management of Directus. Uploading files will assign UUID to each file, and your collection can save the UUID for the file(s).
- Directus can let you configure auto-filled fields like CREATE or UPDATE timestamp. No coding required.
- System objects like “Users”, uploaded “Assets (files)”, etc are also controllable via API with permissions.
With Directus, you focus on database design. API is ready when your database is done.