如何批量生成api呢?
发布于 1 年前 作者 wangsenyan 1164 次浏览 来自 问答
var apiList = {
"/api/enterprise/book": "post",
"/api/enterprise/book/:namespace/:name": "get",
"/api/enterprise/book/:namespace/:name": "put",
"/api/enterprise/book/:namespace/:name": "delete",
"/api/enterprise/book": "get",
"/api/enterprise/book/:namespace/:name/release": "post",
"/api/enterprise/team": "post",
"/api/enterprise/team/:teamname": "put",
"/api/enterprise/team/:teamname": "get",
"/api/enterprise/team/:teamname": "delete",
"/api/enterprise/team": "get"

} for (var i in apiList) { app[apiList[i]](i, function (req, res) { var method = req.method; var pathname = req.url; var body = req.body; console.log(method, pathname, body) var options = getOptions(method, pathname, body); request(options, function (err, resp, body) { if (err) { return res.err(err) } else { return res.ok(body) } }) }) }

这样生成的api,只有简单的get能用,其他不能用,为什么呢?

2 回复

“/api/enterprise/team”: “get” "/api/enterprise/book": “get”, 只有上面的能用

批量生成资源,建议使用amur工具 https://github.com/zhangkaiyulw/amur

回到顶部