Creating Rest API using Sails framework? – User friendly Tech help
What is Sails?
n
n
Pre-reqiuistes:-
n
n
2. Install Sails npm install -g sails ( installing sails package globally)
n
Creating our rest api project :-
n
Step1:- Create Sails project (with no frontend as we are showing api example)
n
sails new –no-frontend
n
nStep2:- It will automatically create our template folders n
Inside api folder > controller is where we have our endpoints defined,
n
Step3:- Lets create a sensor resource with sensor endpoints
n
sails generate api sensor
n
Step4:-Check now our controllers and models folders contains the newly generateid resources named as SensorController.js and Sensor.js
n
Step5:- Define attributes property under api>models>sensor.js
n
say it be “sensorname”: “string”
n
Step6:-Run the sails app
n
sails lift
n
nselect any option from 1,2,3 of databse options when prompt asks
n
nn
Step7:- Check the app in localhost:1337/sensor in browser
n
it will give empty list as we havent defined anything
n
n
Step8:- Sails have autogenerated end points thus open localhost:1337/sensor/create?sensorname=Airsensor
n
n
Step9:- Check that sensorname is getting added to localhost:1337/sensor
Sails Seed project
nLearn Javascript