【发布时间】:2015-10-17 09:27:58
【问题描述】:
我是 NodeJS 和 Sails.js 的新手。
我想创建一个允许我根据查询参数扩展资源的 REST API。例如
HTTP GET /snippets
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"url": "http://localhost:8000/snippets/1/",
"highlight": "htep://localhost:8000/snippets/1/highlight/",
"title": "test",
"code": "def test():\r\n pass",
"linenos": false,
"language": "Clipper",
"style": "autumn",
"owner": "http://localhost:8000/users/2/",
"extra": "http://localhost:8000/snippetextras/1/"
}
]}
HTTP GET /snippets?expand=owner
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"url": "http://localhost:8000/snippets/1/",
"highlight": "http://localhost:8000/snippets/1/highlight/",
"title": "test",
"code": "def test():\r\n pass",
"linenos": false,
"language": "Clipper",
"style": "autumn",
"owner": {
"url": "http://localhost:8000/users/2/",
"username": "test",
"email": "test@test.com"
},
"extra": "http://localhost:8000/snippetextras/1/"
}
]}
想知道如何在 Sails.js 或 NodeJS 中做到这一点?
【问题讨论】:
标签: javascript node.js rest sails.js