---
title: Routing
project: Total.js V4
version: 0.0.99
section: guides
language: en
license: MIT
url: https://totaljs.es/docs/total-js-v4/0-0-99/guides/routing/
updated: 2026-11-16T15:41:00.817Z
---

# Routing

> Methods, dynamic parameters, signed-in users, schemas, API routes, views and flags of ROUTE().

Every route is declared with `ROUTE()`, usually inside `exports.install` of a file in `controllers/`.

```js
exports.install = function() {
	ROUTE('GET /products/', products);
	ROUTE('POST /products/', create);
};
```

The first argument describes the route in one line: **method**, **URL**, and optionally a **schema operation**, **middleware**, **roles** and **flags**. The full list of arguments is in the reference of [ROUTE()](../../reference/routing/).

## Methods

`GET` is the default. Write the method before the URL: `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `HEAD`, `OPTIONS`. Several methods are separated by commas:

```js
ROUTE('GET,POST /contact/', contact);
```

## Dynamic parameters

Parts in braces are parameters. They arrive as arguments of the action, in their order, and in `this.params`:

```js
ROUTE('GET /users/{id}/', read);
ROUTE('GET /blog/{year}/{slug}/', article);

function article(year, slug) {
	// this.params.year, this.params.slug
}
```

A parameter can have a type: `{page:number}`, `{active:boolean}` and `{date:date}` are converted in `this.params`. `{id:uid}` and `{id:guid}` accept only identifiers of that kind.

A `*` at the end of the URL matches the rest of the path:

```js
ROUTE('GET /docs/*', docs);
```

## Signed-in users

`+` before the method allows only requests that your `AUTH()` delegate accepted, and `-` only the others. A role (`@admin`) implies a signed-in user:

```js
ROUTE('+GET /account/', account);
ROUTE('-GET /login/', login);
ROUTE('+GET /admin/ @admin', admin);
```

## Schemas and actions

A route can call operations of a schema without writing an action. `*Schema --> operation` validates the request body with the schema and runs the operation:

```js
ROUTE('POST /api/users/ *Users --> insert');
ROUTE('GET  /api/users/{id}/ *Users --> read');
```

Several operations run one after another. `(response)` after one of them says whose result is sent back:

```js
ROUTE('POST /api/orders/ *Orders --> check insert (response) notify');
```

## API routes

`API` groups many operations behind one URL. The client sends `POST` with `{ "schema": "name/params", "data": {} }`; `+` marks the operations that take data and `-` those that do not:

```js
ROUTE('API /api/ -users_list        *Users --> list');
ROUTE('API /api/ -users_read/{id}   *Users --> read');
ROUTE('API /api/ +users_save        *Users --> save');
```

## Views

An action can be the name of a view. Without an action, the view is chosen from the URL:

```js
ROUTE('GET /about/', 'about');   // views/about.html
ROUTE('GET /pricing/');           // views/pricing.html
```

## Flags

Flags change how a route works. Write them in the URL after a space, or pass them as an array:

```js
ROUTE('POST /upload/', upload, ['upload', 60000], 1024 * 5);
```

- `json`, `xml`, `raw`: the body comes as JSON, XML or raw data (the route becomes `POST`).
- `upload`: the body is `multipart/form-data` with files.
- `cors`, origins (`https://app.com`) and `credentials`: cross-origin requests.
- `csrf`, `referer`: checks the CSRF token or the referer.
- `mobile`, `robot`: only for mobile devices, or only for crawlers.
- `encrypt`: the answer is encrypted.
- `delay`: the request has no timeout.
- `novalidate`: the schema converts the body without validating it.
- A number: the timeout of the request in milliseconds (default `3000`).
- `#name` or `&name`: runs a middleware first.
- `// text`: a description of the route.

## Request size

The last argument limits the size of the request body, in **kilobytes** (default `10`). It is needed for big JSON bodies and uploads:

```js
ROUTE('POST /api/import/ json', importdata, 1024);   // 1 MB
```

## Files and WebSockets

`FILE` routes handle static-like files and `SOCKET` routes open WebSockets; they have their own pages in the reference.

```js
ROUTE('FILE /docs/*.pdf', pdf);
ROUTE('SOCKET /chat/', chat);
```

## Subdomains and removing routes

A route only for a subdomain starts with it in brackets: `ROUTE('[api]/users/', users)`. `ROUTE(url, null)` removes a route that was declared before.
