What is Sails?

Sails is framework built over Express framework of Nodejs which automatically generates structure of rest api. It have numerous other features like supports MVC, connets to any database, supports most of the front end frameworks and many more http://sailsjs.com/features


Pre-reqiuistes:-
2. Install Sails  npm install -g sails ( installing sails package globally)

Creating our rest api project :-
Step1:- Create Sails project (with no frontend as we are showing api example)
sails new –no-frontend

Step2:- It will automatically create our template folders

sails framework folder structure


Inside api folder > controller is where we have our endpoints defined,
api > models, we create the defination for our resoureces that we would be serving
What is the meaining of folder inside sails project?

Step3:- Lets create a sensor resource with sensor endpoints
sails generate api sensor
Step4:-Check now our controllers and models folders contains the newly generateid resources named as SensorController.js and Sensor.js

Step5:- Define attributes property under api>models>sensor.js
say it be “sensorname”: “string”

Step6:-Run the sails app
sails lift

select any option from 1,2,3 of databse options when prompt asks

sails lift command


Step7:- Check the app in localhost:1337/sensor in browser
it will give empty list as we havent defined anything

Step8:- Sails have autogenerated end points thus open localhost:1337/sensor/create?sensorname=Airsensor

Step9:- Check that sensorname is getting added to localhost:1337/sensor
sails results in localhost


Leave a Reply

Your email address will not be published. Required fields are marked *