8000 [Docs] Add routing guidance to the asynchronous process chapter · nelson6e65/laravel-json-api@1e2be41 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e2be41

Browse files
committed
[Docs] Add routing guidance to the asynchronous process chapter
Closes cloudcreativity#320
1 parent 082f61a commit 1e2be41

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

docs/features/async.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,40 @@ class ProcessPodcast implements ShouldQueue
217217
}
218218
```
219219

220+
## Routing
221+
222+
The final step of setup is to enable asynchronous process routes on a resource. These
223+
routes allow a client to check the current status of a process.
224+
225+
For example, if our `podcasts` resource used asynchronous processes when a podcast is
226+
created, we would need to add the following to our [route definitions](../basics/routing.md):
227+
228+
```php
229+
JsonApi::register('default')->withNamespace('Api')->routes(function ($api) {
230+
$api->resource('podcasts')->async();
231+
});
232+
```
233+
234+
This enables the following routes:
235+
236+
- `GET /podcasts/queue-jobs`: this lists all `queue-jobs` resources for the `podcasts`
237+
resource type.
238+
- `GET /podcasts/queue-jobs/<UUID>`: this retrieves a specific 9C8F `queue-jobs` resource
239+
for the `podcasts` resource type.
240+
241+
The resource type `queue-jobs` is the name used in the JSON API's recommendation for
242+
asynchronous processing. If you want to use a resource type, then you can change this
243+
by editing the `jobs.resource` config setting in your API's configuration file.
244+
245+
Note that we assume the resource id of a process is a valid UUID. If you use something
246+
different, then you can pass a constraint into the `async()` method, as follows:
247+
248+
```php
249+
JsonApi::register('default')->withNamespace('Api')->routes(function ($api) {
250+
$api->resource('podcasts')->async('^\d+$');
251+
});
252+
```
253+
220254
## HTTP Requests and Responses
221255

222256
Once you have followed the above instructions, you can now make HTTP requests and receive

0 commit comments

Comments
 (0)
0