Reputation: 3377
I am new to node and new to sails. So this question may be pretty stupid, but I have used the "sails generate prospects" command to generate a REST api. I can access that api by visiting /api/v1/prospects (i set up the prefix).
I used chrome's postman extension to POST the following json array to that api, and it worked perfectly:
{
"contactInfo" : {
"firstName" : "john",
"lastName" : "Stamos",
"company" : "Full House",
"title" : "Owner",
"phone" : "(352) 555-5555",
"email" : "[email protected]",
"website" : "http://fullhouse.com",
"facebookUrl" : "http://facebook.com/fullhouse",
"twitterUrl" : "http://twitter.com/fullhouse",
"linkedInUrl" : "http://linkedin.com/fullhouse",
"backgroundInfo" : "Ken and I first got together when Cynthia needed a web designer!",
"firstContact" : "2014-07-09T12:00:00Z"
},
"address" : {
"address" : "1234 Somewhere Street",
"address2" : "Suite 1",
"city" : "Ocala",
"state" : "FL",
"zipcode" : "35675"
},
"files" : [
{
"filename" : "2345456324-23445745.jpg",
"folder" : "some folders name",
"insDate" : "2014-07-09T12:00:00Z"
},
{
"filename" : "2345332423-3453565462.jpg",
"folder" : "some folders name",
"insDate" : "2014-07-09T12:00:00Z"
}
],
"notes" : [
{
"note" : "She emailed me friday about a new project",
"teamMemberId" : 0,
"insDate" : "2014-07-09T12:00:00Z"
},
{
"note" : "Just talked to her about a proposal.",
"teamMemberId" : 0,
"insDate" : "2014-07-13T12:00:00Z"
}
],
"access" : [],
"blockAccess" : [1],
"ownerId" : 0
}
Here's my question... I was using firebase earlier, and while I know that Firebase is probably a hell of a complicated program and they worked months to get it to work, I love how they have REST endpoints set up within a record. Is this possible out of the box with sails.js?
By that i mean, assuming i imported this same exact json array into firebase, i could query the endpoint:
api/v1/prospects/1/address and I would get back:
{
"address" : "1234 Somewhere Street",
"address2" : "Suite 1",
"city" : "Ocala",
"state" : "FL",
"zipcode" : "35675"
}
or if I queried api/v1/prospects/1/files, I would get back:
[
{
"filename" : "2345456324-23445745.jpg",
"folder" : "some folders name",
"insDate" : "2014-07-09T12:00:00Z"
},
{
"filename" : "2345332423-3453565462.jpg",
"folder" : "some folders name",
"insDate" : "2014-07-09T12:00:00Z"
}
]
Does anyone have any suggestions how I could put together this kind of an API with sails.js or express.js? I want to avoid using firebase for my api, but its looking really tempting unless I can get something like this working. Any tutorials, videos, resources etc where exactly this API scheme are created would be wonderful.
Thanks!
Upvotes: 3
Views: 1440
Reputation: 1358
Honestly, I didn't know whether this was possible or not, but I've tried and I got what you expected, so to make the short answer:
YES! you can do it and it works perfectly (at least in sails 0.10)
Upvotes: 2