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
- 2023-12-01November report 2023
- 2023-11-14How to Use MySQL Database in Total.js with QueryBuilderMySQL
- 2023-11-02October report 2023
- 2023-10-10Headless shopping-cart api tutorial
- 2023-10-06Exploring the Top 5 Open-Source Total.js Apps: Powering Innovation, Collaboration, and Efficiency
- 2023-10-02September report 2023
- 2023-09-02August report 2023
- 2023-08-28Introducing Total.js API Services: Empower Your Applications with Powerful API Endpoints
- 2023-08-15Handling WebSocket Messages in Total.js: A Comprehensive Guide
- 2023-08-11Total.js OpenTemplates