mirror of
https://github.com/flarum/framework.git
synced 2025-02-09 20:48:31 +08:00
![Toby Zerner](/assets/img/avatar_default.png)
- An API action handles a Flarum\Api\Request, which is a simple object containing an array of params, the actor, and optionally an HTTP request object - Most API actions use SerializeAction as a base, which parses request input according to the JSON-API spec (creates a JsonApiRequest object), runs the child class method to get data, then serializes it and assigns it to a JsonApiResponse (standard HTTP response with a Tobscure\JsonApi\Document as content) - The JSON-API request input parsing is subject to restrictions as defined by public static properties on the action (i.e. extensible) - Also the actor is given to the serializer instance now, instead of being a static property
20 lines
456 B
PHP
20 lines
456 B
PHP
<?php namespace Flarum\Api;
|
|
|
|
use Illuminate\Http\Response;
|
|
use Tobscure\JsonApi\Document;
|
|
|
|
class JsonApiResponse extends Response
|
|
{
|
|
public $content;
|
|
|
|
public function __construct($data = null, $status = 200, array $headers = [])
|
|
{
|
|
parent::__construct('', $status, $headers);
|
|
|
|
$this->headers->set('Content-Type', 'application/vnd.api+json');
|
|
|
|
$this->content = new Document;
|
|
$this->content->setData($data);
|
|
}
|
|
}
|