# Group actions in a schema and reuse input definitions

> Use NEWSCHEMA() to declare related actions under one name, and share an input definition between actions with a file in jsonschemas/.

Framework: total5
Product: Total.js 5 (total5@0.0.19)
Language: en
Content-SHA256: 951ce36fc3ea0cd16be8f91ca9a8f5e5b115d12205262a6c67c6e3f7ed178117
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: total5-installed@total5@0.0.19
Review: not-recorded

`NEWSCHEMA(name, fn)` groups the actions of one entity. The function receives the schema object and `schema.action(name, meta)` registers an action called `Name/action`, with the same options as `NEWACTION()` (`input`, `output`, `params`, `user`, `permissions`, `action`...). Everywhere else the action is used by its full name, exactly as if it had been declared with `NEWACTION('Users/insert', ...)`: `ROUTE('POST /users/ --> *Users/insert')` or `ACTION('Users/insert', payload)`.

A fragment of an input definition that several actions share, such as an address, goes in its own file in `jsonschemas/`. A `.txt` file holds the same `name:Type` list as `input`; the name of the file is the name of the schema. Reference it from an `input` with `@Name`, and its fields (and which of them are required) are added to the action's own fields.

```text jsonschemas/Address.txt
*street:String, *city:String, zip:String
```

```js schemas/users.js
NEWSCHEMA('Users', function(schema) {

	schema.action('insert', {
		name: 'Create a user',
		input: '*name:String, @Address',
		output: 'id:UID, name:String, city:String',
		action: function($, model) {
			$.callback({ id: UID(), name: model.name, city: model.city });
		}
	});

	schema.action('count', {
		name: 'Count users',
		action: function($) {
			$.callback({ count: 2 });
		}
	});

});
```

```js controllers/users.js
exports.install = function() {
	ROUTE('POST /users/ --> *Users/insert');
	ROUTE('GET /users/count/ --> *Users/count');
};
```
