As a side note, let me talk about something that developers love: quick wins. Sometimes, you’re able to deliver a shiny new feature or a huge enhancement simply by making small changes to a codebase. This release is probably the exact opposite of that, as I worked on a huge piece that drove me absolutely insane to produce a result that, when not looked at closely, may look thin. Let me show you why it’s not.
Field types
Creating a collection involves specifying the fields and their types. API supports the usual primitive types, like String, Number or Boolean, as well as some compound ones like Mixed, Object or Reference. Each of these fields requires a different treatment from API when it’s processing a query or a document, as each of them will have their own validation, sanitization and formatting routines.
Previously, all this logic lived in the core of the application, in large modules holding all the rules and particularities of every field type. These modules would process documents like an assembly line, spitting out on the other side a document that is ready to be saved to the database or delivered to the consumer.
The problem with this approach is that it became difficult to customize the behavior of a particular field type at a project level, and even more difficult to create a completely new field type. The bulk of the work around the 3.1 release was (the very unsexy task of) breaking that logic out into several field modules, one for each type, compartmentalizing all the validation, sanitization and formatting involved with each type.
In the immediate term, this makes the application easier to maintain and reason about, but what’s really great about it is that it paves the way for the introduction of user-defined fields in a future release. The idea is that API will still ship with a set of pre-defined field types, but allow developers to extend them or build with their own custom implementations as well.
For maximum flexibility and customization, this will take place in the form of modular plug-ins, inline with the approach we’ve taken on data connectors, custom endpoints and collection hooks.
Reference fields
Perhaps the most powerful field implemented by API is called Reference. It allows a collection to reference one or multiple documents from another collection, allowing the system to represent complex one-to-one, one-to-many and many-to-many relationships.
For example, if we were to create a collection of movies, we could represent the cast as a Reference field, indicating the actors collection as the source of the referenced documents.
Updates
Last Updated:
September 2019

