BETA
My accountGet started
Mar 162023
Total.js Platform
1 min read

Total.js API routing: The game changer

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

Documentation