Skip to content

Commit dd00252

Browse files
author
Benoit Tigeot
committed
Add recommendations for asynchronous processing
Started a discussion on discourse about it : http://discuss.jsonapi.org/t/long-running-jobs-or-asynchronous-processing/26 Maybe the status response have too much infos for this example. Maybe "actions" should not be there.
1 parent 301c81d commit dd00252

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

recommendations/index.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,53 @@ that wish to support these clients are recommended to treat `POST` requests as
142142
`PATCH` requests if the client includes the `X-HTTP-Method-Override: PATCH`
143143
header. This allows clients that lack `PATCH` support to have their update
144144
requests honored, simply by adding the header.
145+
146+
147+
## Asynchronous Processing <a href="#asynchronous-processing" id="asynchronous-processing" class="headerlink"></a>
148+
149+
Consider a situation when you need to create a resource and the operation takes long time to complete.
150+
151+
The request **SHOULD** return a status `202 Accepted` with a link in Header/Location.
152+
153+
```text
154+
HTTP/1.1 202 Accepted
155+
Location: https://example.com/photos/queue/5234
156+
Content-Type: application/vnd.api+json
157+
```
158+
159+
The location gave **SHOULD** return `200 Ok` with the status of the selected job. The body **MAY** contains `"actions"` to manage the job.
160+
161+
```json
162+
{
163+
"links": {
164+
"self": "/photos/queue/5234"
165+
},
166+
"data": {
167+
"type": "queue job",
168+
"id": "5234",
169+
"status": "Process failed, see errors",
170+
"errors": [
171+
{
172+
"code": "too_long",
173+
"field": "/photos/title"
174+
},
175+
{
176+
"code": "invalid_format",
177+
"field": "/photos/file01"
178+
}
179+
]
180+
},
181+
"actions": {
182+
"cancel": "/photos/queue/5234/cancel",
183+
"delete": "/photos/queue/5234/delete"
184+
}
185+
}
186+
```
187+
188+
When job process is done the location gave **SHOULD** return `303 See other` with the location of the data in Header/Location.
189+
190+
```text
191+
HTTP/1.1 303 See other
192+
Location: https://example.com/photos/4577
193+
Content-Type: application/vnd.api+json
194+
```

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy