在node.js中自动生成Rest服务 [英] auto generate Rest service in node.js

查看:107
本文介绍了在node.js中自动生成Rest服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以像在rails中那样在node.js中自动生成Rest服务? 我只想将我的mongodb模型公开为Restfull服务.我现在在Mongoose和express-resource上做了很多重复的工作.

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.

推荐答案

是的,可以按照以下命令进行操作:

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

并修改config/routes.js:

and modify config/routes.js:

map.resources('resource', function (res) {
    res.resources('nestedresources');
});

检查此示例应用程序: https://github.com/anatoliychakkaev/railway-example-app

Check this example app: https://github.com/anatoliychakkaev/railway-example-app

欢迎来到铁路: http://railwayjs.com

这篇关于在node.js中自动生成Rest服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆