Handling a maximum number of internal operations with a minimum number of external endpoints with Total.js API Routing mechanism
API routing is Total.js internal mechanism used to expose API endpoints in a very simple way. The mechanism is designed to focus on handling a maximum number of internal operations with a minimum number of external endpoints. Therefore API routing only works with Total.js Schema and their operations.
How does it work?
You can create one endpoint (e.g /api/
) and use it to target an infinite number of operations within your application. All you have to do is call that endpoint with the POST method and have in the body of the request, a JSON payload to specify what operation of what schema to target.
Example :
Download empty project
Declare your API routes
Call endpoint from external
Output
Required The request body is in JSON format and expects two parameters:
schema ---> (schema_name/{dynamic_arg_1}/{dynamic_arg_2}?query=arguments)
to specify schema (supports params and query).
data ---> data payload (optional).
Good to know
The routing can contain two times +/- characters.
First : ROUTE('+API ...')
or ROUTE('-API ...')
for authorization purpose. (Read more here).
Second: +schema_name
or -schema_name
to specify if data reception is expected or not.
Websocket API
Yes. The API Routing supports the WebSocket protocol and we recommend it too. Its declaration is the same as the standard API Routing, except that the route must contain identifiers in the form @YOUR_NAME
instead of the relative URL address. Let us try it:
Declare your Websocket API routes
Other posts from Total.js Platform
- 2024-12-10Total.js UI Builder: How to upload files?
- 2024-12-04Performance Testing: Total.js vs. Koa
- 2024-12-03Total.js UI Builder: Creating a Form
- 2024-12-02November report 2024
- 2024-11-26Total.js V5: Schemas and Actions
- 2024-11-25QueryBuilder in Action Part 1
- 2024-11-13Benchmarking Node.js Frameworks: selecting your framework for 2025!
- 2024-11-01October report 2024
- 2024-10-22Performance Testing: Total.js vs. NestJS
- 2024-10-01September report 2024