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-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
- 2024-09-27Total.js UI Builder: #2 designing your first interface
- 2024-09-26Total.js V5: Middlewares
- 2024-09-23Beginner Guide to Total.js UI: # 05 Client-side routing
- 2024-09-23Total.js UI #4: Data Binding (Part 2 – Practical Example)
- 2024-09-20Introduction to Total.js UI Builder: A Beginner’s Guide
- 2024-09-13Total.js v5: #06 Understanding File Routing