@@ -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 ` 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
222256Once you have followed the above instructions, you can now make HTTP requests and receive
0 commit comments