Introduction
What is Nodeblocks?
Nodeblocks is a low cost application development platform, created to speed up both Front-end and Back-end development of Web and Mobile platforms.
By providing prefabricated services, called Blocks, you can focus your development resources solely on your core business logic and use cases, with a high level of freedom in terms of architecture and integration.
Nodeblocks vs Other solutions
One of the core principles of Nodeblocks is to be transparent and easily extendable. This allows you to focus entirely on your core business logic, but without locking you out of your desired architecture or custom solutions where needed.
Nodeblocks occupies the space between a No-code prefabricated solution, and writing your services entirely from scratch.
Blocks
A single service in Nodeblocks is also known as a Block. These Blocks are individually deployable, independent parts of the system, each with their own processes, databases and functionality. Each Block provides an API which other services and your Front End can interface with. You can pick and choose which Blocks you need for your system freely.
Adapters
Each Block in Nodeblocks is implemented below the surface using an Adapter. These Adapters control how the features of the Block are implemented, defining validation, business logic and communication with external such as the Database and mail providers.
Developers will write their own adapters when they want to customize the default behaviour offered by each service.
In fact, the default behaviour of each service itself is implemented as an adapter called the Default Adapter. The Default Adapter is developed by the Nodeblocks team and is provided as part of the library.
The concept of adapters is similar to the concept of OS drivers.
All Nodeblocks services on startup receive a parameter called adapter
that tells the service what handlers and what
validators will be attached to each endpoint defined by the service.
nodeblocksCatalogApp.startService({ adapter: myAdapter });
Layers
In order to understand how to use adapters to customize services is useful to first look at how requests are processed by each layer in the service.
Each request to a Block in Nodeblocks is passed through the Block's external API to the Adapter, which is broken down into Validators and a Handler for each endpoint on the API.
Validators
Validators, also known as Predicates, are used to configure logic that must pass before an API can be executed by a client request. To give some examples of what validators might do:
- Ensure that an
Authorization
header is provided - Ensure that the provided user is permitted to perform this request
- Ensure the request has the right format
- Applying one of several conditions and passing if at least one is correct
The validators
property of each endpoint on a Block is an array of small predicate functions that return a
Promise<number>
where the number represents an HTTP status.
Each validator for an endpoint takes a Logger
and Context
for the request which can be used to perform the
client's request.
When a validator fails, either an erroring status can be returned, or an error with a custom message can be thrown and returned to the client. For more details, see examples in Customizing Default Adapters
Handlers
The Handler for an endpoint is a function that performs the core business logic, such as CRUD database operations or
calling other services. Just like validators, handlers also take a Logger
and Context
.
For a handler, the response will contain both the data for the response as well as the HTTP status.
{
data?: object | string // The data to be returned by the endpoint
status: number // HTTP status
}
As with validators, the handlers for a default adapter can also be customized as desired. For more details, see examples in Customizing Default Adapters