ForgeTotal.js 5
en

Total.js 5

Filter the response of an action with output

Total.js 5 · total5@0.0.19 actionssecurity Executed against Total.js 5

output has the same syntax as input, but it is applied to the response: only the declared fields are sent, converted to their types. Declare it on every action that reads from a database and you cannot leak a field by accident.

definitions/users.js
NEWACTION('Users/read', {
	name: 'Read a user',
	output: 'id:String, name:String, age:Number',
	action: function($) {
		$.callback({ id: '1', name: 'Peter', age: '42', password: 'secret-hash', token: 'abc' });
	}
});
controllers/users.js
exports.install = function() {
	ROUTE('GET /user/ --> *Users/read');
};