11# Asynchronous Processing
22
3- The JSON API specification
3+ The JSON API specification
44[ provides a recommendation] ( https://jsonapi.org/recommendations/#asynchronous-processing )
5- for how APIs can implement long running processes. For example, if the operation to create a
6- resource takes a long time, it is more appropriate to process the creation using
5+ for how APIs can implement long running processes. For example, if the operation to create a
6+ resource takes a long time, it is more appropriate to process the creation using
77[ Laravel's queue system] ( https://laravel.com/docs/queues )
88and return a ` 202 Accepted ` response to the client.
99
@@ -29,14 +29,14 @@ use Illuminate\Support\ServiceProvider;
2929
3030class AppServiceProvider extends ServiceProvider
3131{
32-
32+
3333 // ...
34-
34+
3535 public function register()
3636 {
3737 LaravelJsonApi::runMigrations();
3838 }
39-
39+
4040}
4141```
4242
@@ -45,7 +45,7 @@ class AppServiceProvider extends ServiceProvider
4545If you want to customise the migrations, you can publish them as follows:
4646
4747``` bash
48- $ php artisan vendor:publish --tag=" json-api- migrations"
48+ $ php artisan vendor:publish --tag=" json-api: migrations"
4949```
5050
5151If you do this, you ** must not** call ` LaravelJsonApi::runMigrations() ` in your service provider.
@@ -76,7 +76,7 @@ use Neomerx\JsonApi\Schema\SchemaProvider;
7676class Schema extends SchemaProvider
7777{
7878 use AsyncSchema;
79-
79+
8080 // ...
8181}
8282```
@@ -112,7 +112,7 @@ class ProcessPodcast implements ShouldQueue
112112{
113113
114114 use ClientDispatchable;
115-
115+
116116 // ...
117117}
118118
@@ -130,7 +130,7 @@ means you can use any of the normal Laravel methods. The only difference is you
130130` dispatch ` method at the end of the chain so that you have access to the process that was stored
131131and can be serialized into JSON by your API.
132132
133- You can use this method of dispatching jobs in either
133+ You can use this method of dispatching jobs in either
134134[ Controller Hooks] ( ../basics/controllers.md ) or within
135135[ Resource Adapters] ( ../basics/adapters.md ) , depending on your preference.
136136
@@ -190,9 +190,9 @@ class Adapter extends AbstractAdapter
190190If a dispatched job creates a new resource (e.g. a new model), there is one additional step you will
191191need to follow in the job's ` handle ` method. This is to link the stored process to the resource that was
192192created as a result of the job completing successfully. The link must exist otherwise your API
193- will not be able to inform a client of the location of the created resource once the job is complete.
193+ will not be able to inform a client of the location of the created resource once the job is complete.
194194
195- You can easily create this link by calling the ` didCreate ` method that the ` ClientDispatchable `
195+ You can easily create this link by calling the ` didCreate ` method that the ` ClientDispatchable `
196196trait adds to your job. For example:
197197
198198``` php
@@ -205,13 +205,13 @@ class ProcessPodcast implements ShouldQueue
205205{
206206
207207 use ClientDispatchable;
208-
208+
209209 // ...
210-
210+
211211 public function handle()
212212 {
213213 // ...logic to process a podcast
214-
214+
215215 $this->didCreate($podcast);
216216 }
217217}
@@ -272,11 +272,11 @@ This enables the following routes:
272272
273273- ` GET /podcasts/queue-jobs ` : this lists all ` queue-jobs ` resources for the ` podcasts `
274274resource type.
275- - ` GET /podcasts/queue-jobs/<UUID> ` : this retrieves a specific ` queue-jobs ` resource
275+ - ` GET /podcasts/queue-jobs/<UUID> ` : this retrieves a specific ` queue-jobs ` resource
276276for the ` podcasts ` resource type.
277277
278278The resource type ` queue-jobs ` is the name used in the JSON API's recommendation for
279- asynchronous processing. If you want to use a resource type, then you can change this
279+ asynchronous processing. If you want to use a resource type, then you can change this
280280by editing the ` jobs.resource ` config setting in your API's configuration file.
281281
282282Note that we assume the resource id of a process is a valid UUID. If you use something
@@ -291,7 +291,7 @@ JsonApi::register('default')->withNamespace('Api')->routes(function ($api) {
291291## HTTP Requests and Responses
292292
293293Once you have followed the above instructions, you can now make HTTP requests and receive
294- asynchronous process responses that following the
294+ asynchronous process responses that following the
295295[ JSON API recommendation.] ( https://jsonapi.org/recommendations/#asynchronous-processing )
296296
297297For example, a request to create a podcast would receive the following response:
0 commit comments