如何为媒体分析引擎设计 RESTful API [英] How to design a REStful API for a media analysis engine
问题描述
我是 Restful 概念的新手,必须为我需要设置的媒体分析服务设计一个简单的 API,以执行各种任务,例如对上传的图片和视频进行人脸分析、区域检测等.
I am new to Restful concept and have to design a simple API for a media analysis service I need to set up, to perform various tasks, e.g. face analysis, region detection, etc. on uploaded images and video.
我最初的设计大纲如下:
Outline of my initial design is as follows:
- 客户端将配置 XML 文件 POST 到
http://manalysis.com/facerecognition
.这将创建一个可用于多个分析会话的配置文件.响应 XML 包含一个ProfileID
以引用此配置文件.客户端可以跳过此步骤使用默认配置参数 - 客户端将要分析的视频数据发布到
http://manalysis.com/facerecognition
(以 ProfileID 作为参数,如果已设置).这将创建一个分析会话.返回 XML 具有SessionID
. - 客户端可以向
http://manalysis.com/facerecognition/SessionID
发送 GET 请求以接收会话状态.
- Client POSTs a configuration XML file to
http://manalysis.com/facerecognition
. This creates a profile that can be used for multiple analysis sessions. Response XML includes aProfileID
to refer to this profile. Clients can skip this step to use the default config parameters - Client POSTs video data to be analyzed to
http://manalysis.com/facerecognition
(with ProfileID as a parameter, if it's set up). This creates an analysis session. Return XML has theSessionID
. - Client can send a GET to
http://manalysis.com/facerecognition/SessionID
to receive the status of the session.
我在正确的轨道上吗?具体来说,我有以下问题:
Am I on the right track? Specifically, I have the following questions:
- 我应该在 URL 中包含
facerecognition
吗?Roy Fielding 说REST API 不能定义固定的资源名称或层次结构"这是该错误的一个实例吗? - 分析结果可以在一个大型 XML 文件中返回给客户端,也可以在检测到每个事件时返回给客户端.我应该如何告诉分析引擎返回结果的位置?
- 我是否应该在分析完成后通过 DELETE 调用明确删除配置文件?
- Should I include
facerecognition
in the URL? Roy Fielding says that "a REST API must not define fixed resource names or hierarchies" Is this an instance of that mistake? - The analysis results can either be returned to the client in one large XML file or when each event is detected. How should I tell the analysis engine where to return the results?
- Should I explicitly delete a profile when analysis is done, through a DELETE call?
谢谢,
C
推荐答案
可以修复入口点url,
You can fix the entry point url,
GET /facerecognition
<FaceRecognitionService>
<Profiles href="/facerecognition/profiles"/>
<AnalysisRequests href="/facerecognition/analysisrequests"/>
</FaceRecognitionService>
通过将 XML 配置文件发布到 Profiles 元素的 href 属性中的 URL 来创建新配置文件
Create a new profile by posting the XML profile to the URL in the href attribute of the Profiles element
POST /facerecognition/profiles
201 - Created
Location: /facerecognition/profile/33
通过创建新的分析请求来启动分析.我会避免使用术语会话,因为它太笼统,并且在 REST 世界中有很多负面关联.
Initiate the analysis by creating a new Analysis Request. I would avoid using the term session as it is too generic and has lots of negative associations in the REST world.
POST /facerecognition/analysisrequests?profileId=33
201 - Created
Location: /facerecognition/analysisrequest/2103
查看进程状态
GET /facerecognition/analysisrequest/2103
<AnalysisRequest>
<Status>Processing</Status>
<Cancel Method="DELETE" href="/facerecognition/analysisrequest/2103" />
</AnalysisRequest>
当处理完成时,同样的GET可以返回
when the processing has finished, the same GET could return
<AnalysisRequest>
<Status>Completed</Status>
<Results href="/facerecognition/analysisrequest/2103/results" />
</AnalysisRequest>
我选择的具体网址比较随意,你可以用你最清楚的.
The specific URLs that I have chosen are relatively arbitrary, you can use whatever is the clearest to you.
这篇关于如何为媒体分析引擎设计 RESTful API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!