营造宁静的方式表决定的资源
问题说明
我需要知道如何决定什么是资源,什么是子资源。我只是有一些表的,我需要做的URI。因此可以说,我有一个学生表,studentclass(这给名字,可能一些学生在就读于类的更多细节)表(N:1)。
I need to know how to decide what is a resource and what is a sub resource. I just have some tables for which i need to make uri's. so lets say i have a student table and studentclass(which gives the name and probably some more details of the class that the student is enrolled in) table with (N:1).
我会让学生就像一个主资源和设计URI低于
I will make student a main resource and design uri like below
http://home/someapi/v1/student/1/
随着建筑URI的休息方法
Following a rest approach for building uri
QUS 1:哪些如下所示的URI做我必须做的访问studentclass
Qus 1: Which uri shown below do i have to make for accessing the studentclass
1.http://home/someapi/v1/studentclass?studentid=1 or
2.http://home/someapi/v1/student/1/studentclass
我要考虑studentclass作为一个单独的资源..?
Do i have to consider studentclass as a separate resource..?
和
QUS 2:假设有N:3 N表之间的关系则URI的设计应如何
Qus 2: Suppose there is N:N relation between tables then how should the design of uri be?
正确答案
我建议处理两个资源:学生
和类
。
I suggest to deal with two resources: student
and class
.
您可以使用以下URI获得学生
:
You can get a student
using the following URI:
http://home/someapi/v1/students/1
Note the plural here, read this article if you want to learn why you should use plural: http://blog.apigee.com/detail/restful_api_design_plural_nouns_and_concrete_names/.
如果一个学生
可以在一个招收类
,它的会是一个这名学生的财产,所以你可以返回下列JSON文档(例如):
If a student
can be enrolled in one class
, it could be a property of this student, so you could return the following JSON document (for example):
{
"student": {
"id": 1,
"firstName": "John",
"lastName": "Doe",
"class": {
"id": 10,
"name": "Room Y"
}
}
}
您可以得到一个特定的类
通过以下网址:
You could get a specific class
with the following URI:
http://home/someapi/v1/classes/10
您可以得到所有的学生都与此URI给定类:
You could get all students for a given class with this URI:
http://home/someapi/v1/classes/10/students
现在,如果你有一个 NN 学生之间的关系
和类
,它会改变我对学生
再在JSON presentation第一个建议。其实,类
关系将成为类
的资源,而不是嵌入一个
Now, if you have a N-N relation between students
and classes
, it would change my first proposal about the student
representation in JSON. Actually, the class
relation would become a collection of class
resources, not an embedded property of a student
, and you should use the following URI:
http://home/someapi/v1/students/1/classes
含义检索所有类学生#1。
Meaning "retrieve all classes for student #1".
您可以公开既类
和学生
资源。无需决定哪一个是主要原因之一,因为他们描述了两种不同的东西。有 /学生
和 /班
允许你创建学生
和类
,你可以将它们链接等。
You can expose both class
and student
resources. No need to decide which one is the main one as they describe two different things. Having /students
and /classes
allows you to create students
and classes
, you can link them, etc.
最后一件事,建议使用查询参数(?富=栏
)用于过滤的目的。
Last thing, it's recommended to use query parameters (?foo=bar
) for filtering purpose.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfggbf
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20