developer-tools/nodejs/porting/1_node_application.md
| HTTP verb | URI | Action |
|---|---|---|
| GET | /message | list all messages |
| GET | /message/ID | get message with ID |
| POST | /message | create a new message |
| PUT | /message/ID | modify message with ID |
| DELETE | /message/ID | delete message with ID |
sudo npm install sails -g (should install 0.12.3)sails new messageApp && cd messageAppnpm install sails-mongo --saveconfig/model.js:
module.exports.models = {
connection: 'mongo',
migrate: 'safe'
};
config/connections.js:
module.exports.connections = {
mongo: {
adapter: 'sails-mongo',
url: process.env.MONGO_URL || 'mongodb://localhost/messageApp'
}
};
sails generate api messagesails liftcurl http://localhost:1337/message[]
Create new messages
curl -XPOST http://localhost:1337/message?text=hellocurl -XPOST http://localhost:1337/message?text=holaGet list of messages
curl http://localhost:1337/message[
{
"text": "hello",
"createdAt": "2015-11-08T13:15:15.363Z",
"updatedAt": "2015-11-08T13:15:15.363Z",
"id": "5638b363c5cd0825511690bd"
},
{
"text": "hola",
"createdAt": "2015-11-08T13:15:45.774Z",
"updatedAt": "2015-11-08T13:15:45.774Z",
"id": "5638b381c5cd0825511690be"
}
]
Modify a message
curl -XPUT http://localhost:1337/message/5638b363c5cd0825511690bd?text=heyDelete a message
curl -XDELETE http://localhost:1337/message/5638b381c5cd0825511690beGet list of messages
curl http://localhost:1337/message[
{
"text": "hey",
"createdAt": "2015-11-08T13:15:15.363Z",
"updatedAt": "2015-11-08T13:19:40.179Z",
"id": "5638b363c5cd0825511690bd"
}
]