Releases: bearsunday/BEAR.Resource
1.7.2
1.7.1
- [ADD] OPTIONS method return json schema by @jsonschema annotation #116
Example:
Resource class
use BEAR\Resource\Annotation\JsonSchema;
use BEAR\Resource\ResourceObject;
class User extends ResourceObject
{
/**
* User
*
* Returns a variety of information about the user specified by the required $id parameter
*
* @param string $id User ID
*
* @JsonSchema(schema="user.json")
*/
public function onGet($id)
{
// $this->body = '$user;
return $this;
}
}
Json Schema
user.json
{
"type": "object",
"properties": {
"name": { "$ref": "name.json#/definitions/name"},
"age": {
"description": "Age in years",
"type": "integer",
"minimum": 20
}
},
"required": ["name", "age"]
}
name.json
{
"title": "Name",
"definitions": {
"name": {
"type": "object",
"properties": {
"firstName": {"type": "string"},
"lastName": {"type": "string"}
},
"required": ["firstName", "lastName"]
}
}
}
Request
OPTIONS /user
Response includes request and response meta information .
{
"GET": {
"summary": "User",
"description": "Returns a variety of information about the user specified by the required $id parameter",
"request": {
"parameters": {
"id": {
"type": "string",
"description": "User ID"
}
},
"required": [
"id"
]
},
"schema": {
"type": "object",
"properties": {
"name": {
"$ref": "name.json#/definitions/name"
},
"age": {
"type": "integer",
"description": "Age in years",
"minimum": 20
}
},
"required": [
"name",
"age"
]
}
}
}
Install
$this->install(JsonSchemalModule($jsonSchemaDir, $jsonValidateDir))
1.7.0
1.6.2
1.6.1
1.6.0
1.5.3
1.5.1
1.5.0
- [ADD] RFC 2616 OPTIONS method payload #95 #99
- [ADD] OptionsMethodModule #96
- [ADD] @ResourceParam template URI support #97
- [ADD] http constant package koriym/http-constant
- [FIX] Disallow @ResourceParam and @assisted parameter by
withQuery()
query #98
RFC 2616 - HTTP/1.1 specification section 9.2 page 51 OPTIONS
The response body, if any, SHOULD also include information about the communication options. The format for such a body is not defined by this specification, but might be defined by future extensions to HTTP.
The payload of OPTIONS method is generated from method signature and PHPDOC. You would not need extra work to provide specifications.
/**
* Todos list
*
* Returns the todos list specified by status
*
* @param string $status todo status
*/
public function onGet(string $status = null) : ResourceObject
{
// ....
}
/**
* Create todo
*
* Create todo and add to todos list
*
* @param string $title todo title
*
*/
public function onPost(string $title) : ResourceObject
{
// ....
}
The result of http OPTIONS method request.
curl -i -X OPTIONS http://127.0.0.1:8080/
HTTP/1.1 200 OK
Host: 127.0.0.1:8080
Date: Tue, 16 May 2017 03:48:50 +0200
Connection: close
X-Powered-By: PHP/7.1.0
Content-Type: application/json
allow: GET, POST
200 OK
Content-Type: application/json
allow: GET, POST
{
"GET": {
"summary": "Todos list",
"description": "Returns the todos list specified by status",
"parameters": {
"status": {
"description": "todo status",
"type": "string"
}
}
},
"POST": {
"summary": "Create todo",
"description": "Create todo and add to todos list",
"parameters": {
"title": {
"description": "todo title",
"type": "string"
}
},
"required": [
"title"
]
}
}
An options command works in console as well as web.
php bootstrap/web.php options /
200 OK
Content-Type: application/json
allow: GET, POST
{
"GET": {
@ResourceParam
supports uri template.
The result of resource request app://self/rparam/login{?name}#nickname
is injected to theid
parameter.
/**
* @ResourceParam(param="id", uri="app://self/rparam/login{?name}#nickname", templated=true)
*/
public function onPost($id, $name)
{
1.4.7
This release fix the issue #94
class Holder extends ResourceObject
{
public function __construct(ResourceInterface $resource)
{
$resource->get->uri('app://self/author?id=1')->eager->request();
}
public function onPost()
{
return true;
}
}
When constructor has another resource request, request method was shared with two resource request client because it is injected as a singleton. This PR fix the issue.
This issue is appeared when the form which has resource request in init()
injected resource client.