Is there a way to auto generate a Rest service in node.js like in rails? I just want to expose my mongodb models as a Restfull service. I am now doing a lot of repetitive work with Mongoose and express-resource.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Yep, it's possible, follow this commands:
npm install railway
railway init rest-app && cd rest-app && npm install
railway generate scaffold resource property1 property2
railway server 3000
That's it! If you need to generate nested resource:
railway generate resource.nestedresource propertyForNestedResource
and modify config/routes.js:
map.resources('resource', function (res) {
res.resources('nestedresources');
});
Check this example app: https://github.com/anatoliychakkaev/railway-example-app
Welcome to railway: http://railwayjs.com
回答2:
You can also use a library I developed if Railway is too bulky for your needs:
https://github.com/enyo/mongo-rest
It's a simple library, well tested, that just provides a REST interface for your mongoose models.