You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A good API is one of most effective ways to improve the experience for your clients. Standardized approaches for data formats and communication protocols increase productivity and make integration between applications smooth.
12
11
13
-
This framework agnostic package implements [JSON API](http://jsonapi.org/) specification **version v1.0** and helps focusing on core application functionality rather than on protocol implementation. It supports document structure, errors, data fetching as described in [JSON API Format](http://jsonapi.org/format/) and covers parsing and checking HTTP request parameters and headers. For instance it helps to correctly respond with ```Unsupported Media Type``` (HTTP code 415) and ```Not Acceptable``` (HTTP code 406) to invalid requests. You don't need to manually validate all input parameters on every request. You can configure what parameters are supported by your services and this package will check incoming requests automatically. It greatly simplifies API development and fully support specification. In particular
12
+
This framework agnostic package implements [JSON API](http://jsonapi.org/) specification **version v1.1** and helps focusing on core application functionality rather than on protocol implementation. It supports document structure, errors, data fetching as described in [JSON API Format](http://jsonapi.org/format/) and covers parsing and checking HTTP request parameters and headers. For instance it helps to correctly respond with ```Unsupported Media Type``` (HTTP code 415) and ```Not Acceptable``` (HTTP code 406) to invalid requests. You don't need to manually validate all input parameters on every request. You can configure what parameters are supported by your services and this package will check incoming requests automatically. It greatly simplifies API development and fully support specification. In particular
14
13
15
14
* Resource attributes and relationships
16
15
* Polymorphic resource data and relationships
17
16
* Compound documents with inclusion of related resources (circular resource references supported)
18
17
* Meta information for document, resources, errors, relationship and link objects
18
+
* Profiles
19
19
* Parsing HTTP `Accept` and `Content-Type` headers in accordance with [RFC 7231](https://tools.ietf.org/html/rfc7231)
20
20
* Parsing HTTP query parameters (e.g. pagination, sorting and etc)
21
21
* Sparse fieldsets and customized included paths
22
22
* Errors
23
23
24
-
High code quality and **100% test coverage** with **200+ tests**. Production ready.
24
+
High code quality and **100% test coverage** with **150+ tests**. Production ready.
25
25
26
26
**To find out more, please check out the [Wiki](https://github.com/neomerx/json-api/wiki) and [Sample App](/sample)**.
27
27
@@ -50,8 +50,10 @@ Assuming you've got an ```$author``` of type ```\Author``` you can encode it to
50
50
51
51
```php
52
52
$encoder = Encoder::instance([
53
-
'\Author' => '\AuthorSchema',
54
-
], new EncoderOptions(JSON_PRETTY_PRINT, 'http://example.com/api/v1'));
@@ -79,36 +88,50 @@ The ```AuthorSchema``` provides information about resource's attributes and migh
79
88
```php
80
89
class AuthorSchema extends BaseSchema
81
90
{
82
-
protected $resourceType = 'people';
91
+
public function getType(): string
92
+
{
93
+
return 'people';
94
+
}
83
95
84
96
public function getId($author): ?string
85
97
{
86
-
/** @var Author $author */
87
98
return $author->authorId;
88
99
}
89
100
90
-
public function getAttributes($author, array $fieldKeysFilter = null): ?array
101
+
public function getAttributes($author): iterable
91
102
{
92
-
/** @var Author $author */
93
103
return [
94
-
'first_name' => $author->firstName,
95
-
'last_name' => $author->lastName,
104
+
'first-name' => $author->firstName,
105
+
'last-name' => $author->lastName,
106
+
];
107
+
}
108
+
109
+
public function getRelationships($author): iterable
110
+
{
111
+
return [
112
+
'comments' => [
113
+
self::RELATIONSHIP_LINKS_SELF => false,
114
+
self::RELATIONSHIP_LINKS_RELATED => true,
115
+
116
+
// Data include supported as other cool features
117
+
// self::RELATIONSHIP_DATA => $author->comments,
118
+
],
96
119
];
97
120
}
98
121
}
99
122
```
100
123
101
-
The first ```EncoderOptions```parameter ```JSON_PRETTY_PRINT``` is a PHP predefined [JSON constant](http://php.net/manual/en/json.constants.php).
124
+
Parameter ```http://example.com/api/v1```is a URL prefix that will be applied to all encoded links unless they have a flag set telling not to add any prefixes.
102
125
103
-
The second ```EncoderOptions```parameter ```http://example.com/api/v1``` is a URL prefix that will be applied to all encoded links unless they have ```$treatAsHref``` flag set to ```true```.
126
+
Parameter ```JSON_PRETTY_PRINT```is a PHP predefined [JSON constant](http://php.net/manual/en/json.constants.php).
104
127
105
128
A sample program with encoding of multiple, nested, filtered objects and more is [here](sample).
106
129
107
130
**For more advanced usage please check out the [Wiki](https://github.com/neomerx/json-api/wiki)**.
108
131
109
132
## Versions
110
133
111
-
Current version is 2.x (PHP 7.1+) for older PHP (PHP 5.5 - 7.0, HHVM) please use version 1.x.
134
+
Current version is 3.x (PHP 7.1+) for older PHP (PHP 5.5 - 7.0, HHVM) please use version 1.x.
- Copy `blackfire.io.env.sample` to `blackfire.io.env`;
12
+
- Put your Client ID, Client Token, Server ID and Server Token to `blackfire.io.env` from [Blackfire.io credentials page](https://blackfire.io/my/settings/credentials) (registration needed).
13
+
14
+
## Profile Performance
15
+
16
+
```bash
17
+
$ docker-compose run --rm cli_php blackfire run php -d zend.assertions=-1 /app/sample/sample.php -t=100
18
+
```
19
+
20
+
The output will contain basic performance info and a URL with detailed profiling info [such as this one](https://blackfire.io/profiles/207fb294-d851-48ad-a31c-db29478172e3/graph).
21
+
22
+
> Note: The **first** run will download necessary docker images which takes some time. The subsequent runs will not require such downloads and be faster.
23
+
24
+
The created container can be removed from the local machine with
0 commit comments