2015-06-19 4 views
4

Я хотел бы правильно спроектировать свой json API с помощью long running jobs с Blueprint. Мне нужно обработать файлы, вернуть 202 Accepted с заголовком местоположения, а затем создать временное местоположение, которое получит 303 See Other, а затем конечный объект 201 Created.Api Blueprint and long running jobs

Есть ли способ правильно спроектировать эту последовательность?

ответ

6

светокопию может выглядеть следующим образом:

# Stars [/stars] 

Collection of stars. 

## Create [POST] 
+ Request (application/json) 

    Create a star 

    + Body 

      {"name": "Death Star"} 

+ Response 202 

    Request has been accepted into the queue. Poll the queue item to check the result. 

    + Headers 

      Location: /queue/12345 


# Queue Item [/queue/{id}] 

One item in a job queue. 

+ Parameters 
    + id: 12345 (number) - Id of the queue 

## Query Status [GET] 
+ Response 200 (aplication/xml) 

    The job is still in progress. 

    + Body 

      <response> 
       <status>PENDING</status> 
       <eta>2 mins.</eta> 
       <link rel="cancel" method="delete" href="/queue/12345" /> 
      </response> 

+ Response 303 

    The job has finished. See the created resource. 

    + Headers 

      Location: /stars/97865