我正在构建一个REST API,我有"Books"和"Users".他们只能存在一本独特的书.虽然用户可以拥有多本书籍,但不同的用户可以拥有相同的书籍(或引用相同的书籍).用户可以向书籍添加其他信息(例如评级).
我的问题是:当用户使用自己的设置"扩展"现有的Book资源时,映射资源的正确方法是什么?
示例:第一次用户没有书籍,但他们可以创建书籍.如果Book不存在则会创建它,如果它存在则可以访问它.虽然他们可以添加自己的私人附加信息.
这是一种正确的方法吗?
//所有包含基本必需信息的书籍都可以在/ books /:id上找到示例:/ books/1 {
"id":1,
"title":"The Empire",
"description":"Description about the book",
"serial":1234
Run Code Online (Sandbox Code Playgroud)
}
//如果用户创建了"The Empire"一书(序列号:1234),他们正在扩展现有的书籍,但他们已经添加了其他信息,因此它实际上是一个新的URL但是引用了书籍ID.
示例:/ users/421/books/1 /
{
"id":1,
"title":"The Empire",
"description":"Description about the book",
"serial":1234,
"rating":5.5,
"note":"I liked the book but it was too long."
}
Run Code Online (Sandbox Code Playgroud)
甚至:
{
"book":{
id":1,
"title":"The Empire",
"description":"Description about the book",
"serial":1234,
}
"rating":5.5,
"note":"I liked the book but it was too long."
}
Run Code Online (Sandbox Code Playgroud)
或者甚至像/ users/421/books/1/settings /这样的网址
{
"rating":5.5,
"note":"I liked the book but it was too …Run Code Online (Sandbox Code Playgroud) 我正在尝试更多地转向我的javascript应用程序中的函数式编程.我目前使用库ramda作为基础库.
我的愿望:
条件:
包含嵌套用户对象的列表:
[{
providers: {
github: {
login: "username1"
}
}
},
{
providers: {
github: {
login: "username2"
}
}
}]
Run Code Online (Sandbox Code Playgroud)
到目前为止实现:
var list = [{providers: {github: {login: "username1"}}},
{providers: {github: {login: "username2"}}}];
var getLoginName = R.useWith(R.path('providers.github.login'));
var isLoginNameEq = R.useWith(R.eq, getLoginName);
isLoginNameEq(list[0], "username1") // => true
//From this point on I am totally clueless,
//but I believe I should combine these functions
//with R.reject in some way.
Run Code Online (Sandbox Code Playgroud)
Plunkr演示:
http://plnkr.co/edit/1b5FjxV3Tcgz7kozW1jX
题:
是否有更好的函数来实现类似于R.eq的东西,但是在嵌套对象(也许是R.pathEq)上?