json-api-server icon indicating copy to clipboard operation
json-api-server copied to clipboard

Support responding with 202 Accepted status

Open tobyzerner opened this issue 6 years ago • 0 comments
trafficstars

As per: https://jsonapi.org/format/#crud-creating-responses-202 https://jsonapi.org/format/#crud-updating-responses-202 https://jsonapi.org/format/#crud-deleting-responses-202 https://jsonapi.org/recommendations/#asynchronous-processing

class PhotosResource implements Creatable
{
    public function create(object $model, Context $context)
    {
        $job = dispatch_create_job($model);

        return new Tobyz\JsonApi\Endpoint\Status\Accepted('queue-jobs', $job);
    }
}

class QueueJobsResource
{
    public function find(string $id, Context $context)
    {
        $job = find_job($id);

        if ($job->finished) {
            return new Tobyz\JsonApi\Endpoint\Status\SeeOther('photos', $job->photo);
        }

        return $job;
    }
}

tobyzerner avatar Dec 14 '18 02:12 tobyzerner