Sails.js Simple REST API - Sails Typing CST Test
Loading…
Sails.js Simple REST API — Sails Code
Demonstrates a simple Sails.js setup with a Todo model and RESTful routes for CRUD operations.
// api/models/Todo.js
module.exports = {
attributes: {
title: { type: 'string', required: true },
completed: { type: 'boolean', defaultsTo: false }
}
};
// api/controllers/TodoController.js
module.exports = {
list: async function(req, res) {
return res.json(await Todo.find());
},
create: async function(req, res) {
const todo = await Todo.create(req.body).fetch();
return res.json(todo);
}
};
// config/routes.js
module.exports.routes = {
'GET /todos': 'TodoController.list',
'POST /todos': 'TodoController.create'
};Sails Language Guide
Sails.js is a Node.js MVC framework designed for building data-driven APIs, service-oriented architectures, and real-time web applications quickly and efficiently.
Primary Use Cases
- ▸Building RESTful APIs quickly
- ▸Real-time apps using WebSockets
- ▸Enterprise backend services
- ▸Data-driven dashboards and analytics
- ▸Rapid prototyping of Node.js web applications
Notable Features
- ▸Auto-generated REST APIs from models
- ▸WebSocket and real-time data support
- ▸Waterline ORM with multiple database adapters
- ▸Policies and hooks for request lifecycle control
- ▸Convention-over-configuration for rapid development
Origin & Creator
Created by Mike McNeil in 2012, Sails.js is maintained by the Balderdash and Sails community.
Industrial Note
Sails.js excels in building real-time dashboards, multiplayer games, chat apps, and API-driven SaaS platforms requiring rapid development and WebSocket integration.