有什么想法我如何使用 Redmine 和 nodejs 创建rest api。我使用了node-redmine,但我不知道如何创建 rest api。我也谷歌,但没有任何办法,因为我不了解 redmine
问问题
1211 次
1 回答
1
Redmine 已经自带了 Rest API。
要使用 API,您需要进入 Redmine 到Administration | 设置 | API并勾选 Enable rest services and JSONP support,然后在My account下找到您的 API 密钥,并按照 node-redmine 库的示例文档中提供的方式使用它
var Redmine = require('node-redmine');
var hostname = process.env.REDMINE_HOST || 'redmine.zanran.me';
var config = {
apiKey: process.env.REDMINE_APIKEY || 'bed1ba0544b681e530c2447341607f423c9c8781'
};
var redmine = new Redmine(hostname, config);
/**
* Dump issue
*/
var dump_issue = function(issue) {
console.log('Dumping issue:');
for (var item in issue) {
console.log(' ' + item + ': ' + JSON.stringify(issue[item]));
}
};
要使用它的 REST API,请使用此处给出的说明和端点: http ://www.redmine.org/projects/redmine/wiki/Rest_api
要创建新问题:
/*
* create issue
*/
var issue = {
"issue": {
"project_id": 1,
"subject": 'Redmine REST API by Node.js',
"assigned_to_id": 5,
"notes": "automative update redmine notes by node js",
"priority_id": 4
}
};
redmine.create_issue(issue, function(err, data) {
if (err) throw err;
console.log(data);
});
但是,如果您仍然坚持创建自己的 API,那么我建议您直接使用 nodejs 连接到 Redmine 的数据库并构建自己的 API,因此您不要为 Redmine 的 API 构建代理。
于 2017-11-30T11:26:43.057 回答