HTTP状态202
表示已接受处理请求,但处理尚未完成。当实际操作本质上是异步时,此状态代码很有用。
其目的是允许服务器接受对某些其他进程的请求(可能是每天只运行一次的面向批处理的进程),而不要求用户代理与服务器的连接持续到进程完成为止。
通过此响应返回的实体应该描述请求的当前状态,并指向(或嵌入)状态监视器,该监视器可以向用户提供(或不具有)对请求何时将被满足的估计。
如果您向REST API提交了长时间运行的异步作业,那么API可以返回如下结果:
HTTP STATUS 202 (Accepted)
{
"task": {
"href": "/api/company/job-management/jobs/2130040",
"id": "2130040"
}
}
现在,用户代理可以定期向URI 发送HTTP GET请求,以/api/company/job-management/jobs/2130040
获得作业的完成状态。上述API的响应将通知实际预定操作的当前状态。
{
"job" : {
"@uri" : "/api/company/job-management/jobs/2130040" ,
"id" : "2130040",
"name" : "Update Resource",
"job-state" : "SCHEDULED",
"job-status" : "UNDETERMINED",
"percent-complete" : "0",
"scheduled-start-time" : "01-01-2013 10:50:45 PM GMT",
"start-time" : "",
"end-time" : "",
"owner" : "Admin",
"summary" : "random text"
}
}
{
"job" : {
"@uri" : "/api/company/job-management/jobs/2130040" ,
"id" : "2130040",
"name" : "Update Resource",
"job-state" : "STARTED",
"job-status" : "INPROGRESS",
"percent-complete" : "30",
"scheduled-start-time" : "01-01-2013 10:50:45 PM GMT",
"start-time" : "01-01-2013 10:50:55 PM GMT",
"end-time" : "",
"owner" : "Admin",
"summary" : "random text"
}
}
{
"job" : {
"@uri" : "/api/company/job-management/jobs/2130040" ,
"id" : "2130040",
"name" : "Update Resource",
"job-state" : "COMPLETED",
"job-status" : "SUCCESS",
"percent-complete" : "100",
"scheduled-start-time" : "01-01-2013 10:50:45 PM GMT",
"start-time" : "01-01-2013 10:50:55 PM GMT",
"end-time" : "01-01-2013 10:52:18 PM GMT",
"owner" : "Admin",
"summary" : "random text"
}
}
以上示例仅供参考。
Powered by RESTful API 中文网 + with by 全栈开发网. 网站地图 按Ctrl+D试试 .