In SailsJS, if you define a Model and a Controller with the same Model name, then Sails will automatically setup a RESTful interface for your model using blueprints.
Our appdev tools: appdev resource ... and appdev table2model ... create both a server side model instance, and a corresponding controller for that model. When sails loads, your new model should have a RESTful interface running.
For this example lets assume that
- you created a new plugin named
opstool-emailNotification:appdev opstoolplugin opstool-emailNotification - you created a new model named
ENRecipient:appdev resource opstools/EmailNotification ENRecipient title:string recipients:text
Now start sails:
# in your [sailsRoot]
$ sails liftOpen up a web browser, and put this in for the url: http://localhost:1337/opstool-emailNotification/enrecipient
NOTE: the default format for accessing your blueprint models is :
get /:modelIdentityorget /:modelIdentity/:idHowever, in our appdev plugin format, we need to prefix the model with the plugin name:
get /:pluginName/:modelIdentityso in this case, our plugin was
opstool-emailNotificationso our url is:/opstool-emailNotification/:modelIdentity
You should see the following response in your browser:
[
{
"title": "X-Men",
"recipients": "profX@email.com, cyclopse@email.com",
"id": 1,
"createdAt": "2015-03-27T06:43:11.000Z",
"updatedAt": "2015-03-27T06:43:11.000Z"
},
{
"title": "Avengers",
"recipients": "capt@email.com, hulk@email.com",
"id": 2,
"createdAt": "2015-03-27T06:43:11.000Z",
"updatedAt": "2015-03-27T06:43:11.000Z"
}
]< Test the Server Side Model
Next: update the Client side Model >