Since the beginning of hellosails.com, there have been articles on the following topics: The basic structure of a Sails.js application Blueprints Policies Validations and Validation Messages Services The above should provide enough knowledge to understand how to build something (relatively small) with a real use case. So today, we're gonna build simple authentication for our Sails API from scratch. There are other tools one can use to (greatly) ease the process of implementing...

Sails.js Policies are pretty simple tools for controlling “who can do what” in your application. They let you allow or deny access to your controllers (and their actions) with nuance. Policies can be used to check if a request isAuthenticated before letting it through or if a User canEdit before updating another post. In fact, you can use (two) Policies to check if a request isAuthenticated AND if the User canEdit. They’re meant...

Sails.js comes pre-packed with quite a number of things that make life easier. Blueprints are one of them. They take the stress out of creating routes and actions in your API. Because Blueprints do a lot of awesome things automagically, it's important to know exactly what they do, when to use them and when not to. Whenever you create a new Sails.js application, Blueprints are turned on automatically. You can either turn them...

Services in Sails.js are pretty easy to understand. They're simply JavaScript objects with functions that can be used everywhere (controllers, policies ... etc). Services live in the /api/services folder. To illustrate this, we'll look at a ResponseService I found lurking in my friend's code. What this service's function does is to sort of format your API's request responses into this neat structure below: { "response": { "message": "User created successfully", "data": { "user": { "id": 8 } } "meta":{ ... // meta...

Data/model validation is a huge part of any API or application and it's thankfully, very easy to set up in Sails.js. Model Validations To illustrate how model level validations work in Sails.js, let us create a new API project and a User model. sails new validationapp --no-frontend sails generate new model User The first thing one would like to validate for a model attribute is the type of that attribute and sails...