Skip to content

Commit 8a2ebf1

Browse files
committed
Updated changelog, readme and upgrade, removed method addApiHandler
1 parent 4d2bac1 commit 8a2ebf1

File tree

4 files changed

+39
-40
lines changed

4 files changed

+39
-40
lines changed

CHANGELOG.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
66

77
#### Changed
88

9-
* Update nette libs to version 3.0.0 (BC break)
9+
* Updated nette libs to version 3.0.0 (BC break)
1010
* Added typehints (BC break)
1111
* Splitted InputParam to multiple subclasses (BC break)
1212
* Removed type TYPE_POST_JSON_KEY (BC break)
1313
* Wrong input now returns code 400 instead of 500 (BC break if somebody checks return code)
14+
* Replaced handler information array triplet (endpoint, handler, authorization) with class Api (BC break for API console usage)
15+
* Renamed some methods from ApiDecider (BC break)
1416
* Pretty JSON output in API console - without escaping unicode and slashes
15-
* Replaced handler information array triplet (endpoint, handler, authorization) with Api
1617

1718
#### Added
1819

@@ -24,13 +25,13 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
2425
#### Removed
2526

2627
* Removed support for PHP 5.6, 7.0 and hhvm (BC Break)
28+
* Removed deprecated class ApiResponse (BC Break)
2729

2830
## 1.15.0 - 2019-03-13
2931

3032
#### Added
3133

3234
* Added possibility to set own scope to Manager
33-
3435
* Added JSON validation - if JSON is invalid, throw "wrong input" error instead of setting params to null
3536

3637
## 1.14.0 - 2018-08-02

README.md

+19-19
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
## Why Nette-Api
1414

15-
This library provides out-of-the box API solution for Nette framework. You can register API endpoints and connect it to specified handlers. You need only implement you custom business logic. Library provide authorization, validation and formatting services for you API.
15+
This library provides out-of-the box API solution for Nette framework. You can register API endpoints and connect it to specified handlers. You need only implement your custom business logic. Library provides authorization, validation and formatting services for you API.
1616

1717
## Installation
1818

@@ -21,7 +21,7 @@ This library requires PHP 7.1 or later.
2121
Recommended installation method is via Composer:
2222

2323
```bash
24-
$ composer require tomaj/nette-api
24+
composer require tomaj/nette-api
2525
```
2626

2727
Library is compliant with [PSR-1][], [PSR-2][], [PSR-3][] and [PSR-4][].
@@ -33,7 +33,7 @@ Library is compliant with [PSR-1][], [PSR-2][], [PSR-3][] and [PSR-4][].
3333

3434
## How Nette-API works
3535

36-
First you have register library presenter for routing. In *config.neon* just add this line:
36+
First, you have to register library presenter for routing. In *config.neon* just add this line:
3737

3838
```neon
3939
application:
@@ -47,7 +47,7 @@ And add route to you RouterFactory:
4747
$router[] = new Route('/api/v<version>/<package>[/<apiAction>][/<params>]', 'Api:Api:default');
4848
```
4949

50-
After that you need only register your api handlers to *apiDecider* [ApiDecider](src/ApiDecider.php) and register [ApiLink](src/Link/ApiLink.php) and [Tomaj\NetteApi\Misc\IpDetector](src/Misc/IpDetector.php). This can be done also with *config.neon*:
50+
After that you need only register your API handlers to *apiDecider* [ApiDecider](src/ApiDecider.php), register [ApiLink](src/Link/ApiLink.php) and [Tomaj\NetteApi\Misc\IpDetector](src/Misc/IpDetector.php). This can be done also with *config.neon*:
5151

5252
```neon
5353
services:
@@ -67,13 +67,13 @@ This example will prepare these API calls:
6767
2. `http://yourapp/api/v1/users/send-email` - available via POST
6868

6969

70-
Core of the Nette-Api are handlers. For this example you need implement 2 classes:
70+
Core of the Nette-Api are handlers. For this example you need to implement two classes:
7171

7272
1. App\MyApi\v1\Handlers\UsersListingHandler
7373
2. App\MyApi\v1\Handlers\SendEmailHandler
7474

75-
These handlers implement interface *[ApiHandlerInterface](src/Handlers/ApiHandlerInterface.php)* but for easier usage you can extends your handlers from [BaseHandler](src/Handlers/BaseHandler.php).
76-
When someone reach your API this handlers will be triggered and *handle()* method will be called.
75+
These handlers implement interface *[ApiHandlerInterface](src/Handlers/ApiHandlerInterface.php)* but for easier usage you can extend your handlers from [BaseHandler](src/Handlers/BaseHandler.php).
76+
When someone reach your API these handlers will be triggered and *handle()* method will be called.
7777

7878
```php
7979
namespace App\MyApi\v1\Handlers;
@@ -108,13 +108,13 @@ This simple handler is using *UsersRepository* that was created by Nette Contain
108108
## Advanced use (with Fractal)
109109

110110
Nette-Api provides integration with [Fractal][] library for formatting API responses.
111-
If you want to use it, you have to extend your handler from *[BaseHandler](src/Handlers/BaseHandler.php)* and your Fractal instance will be accessible be `$this->getFractal()`.
111+
If you want to use it, you have to extend your handler from *[BaseHandler](src/Handlers/BaseHandler.php)* and your Fractal instance will be accessible by `$this->getFractal()`.
112112

113-
Main advantage from Fractal is separation your api "view" (like transformation data to json object or xml or anything...). Also you can include transformations in other transformations to include other objects to others.
113+
Main advantage of Fractal is separation of your API "view" (like transformation data to json object or xml or anything...). Also you can include transformations in other transformations to include other objects to others.
114114

115115
Example with fractal:
116116

117-
1. You will need Formater
117+
1. You will need Transformer
118118

119119
```php
120120
namespace App\MyApi\v1\Transformers;
@@ -165,13 +165,13 @@ class UsersListingHandler extends Basehandler
165165
}
166166
```
167167

168-
I have to recommend to take a look at [Fractal][] library. There are much more information about transformers, serialisers, paginations etc. It is really nice library.
168+
We recommend to take a look at [Fractal][] library. There are much more information about transformers, serializers, paginations etc. It is really nice library.
169169

170170
[Fractal]: http://fractal.thephpleague.com/
171171

172172
## Endpoint inputs
173173

174-
Each handler can describe which input is required. It could be GET or POST parameters, also COOKIES, raw post json or file uploads. You have to implement method `params()` where you have to return array with params. This params are used in api console to generate right form.
174+
Each handler can describe which input is required. It could be GET or POST parameters, also COOKIES, raw post, JSON or file uploads. You have to implement method `params()` where you have to return array with params. These params are used in API console to generate form.
175175

176176
Example with user detail:
177177

@@ -217,26 +217,26 @@ class UsersDetailHandler extends Basehandler
217217

218218
## Input Types
219219

220-
Nette-Api provides various InputParam types. You can send params with GET, POST, COOKIES, FILES or RAW POST data.
220+
Nette-Api provides various InputParam types. You can send params with GET, POST, COOKIES, FILES, RAW POST data or JSON.
221221
All input types are available via test console.
222222

223-
This is table with support input types:
223+
This is table with supported input types:
224224

225225
| Input type | Example
226226
| ---------- | -------
227-
| POST | `new PostInputParam('key')`
228227
| GET | `new GetInputParam('key')`
229-
| FILE | `new FileInputParam('key')`
228+
| POST | `new PostInputParam('key')`
230229
| COOKIE | `new CookieInputParam('key')`
230+
| FILE | `new FileInputParam('key')`
231231
| RAW POST | `new RawInputParam('key')`
232232
| JSON | `new JsonInputParam('key', '{"type": "object"}')`
233233

234234

235235
## Security
236236

237-
Protecting your api is easy with Nette-Api. You have to implement your [Authorization](src/Authorization/ApiAuthorizationInterface.php) (Tomaj\NetteApi\Authorization\ApiAuthorizationInterface) and add it as third argument to *addApi()* method in *config.neon*.
237+
Protecting your API is easy with Nette-Api. You have to implement your [Authorization](src/Authorization/ApiAuthorizationInterface.php) (Tomaj\NetteApi\Authorization\ApiAuthorizationInterface) and add it as third argument to *addApi()* method in *config.neon*.
238238

239-
For simple use, if you want to use Bearer token authorisation with few tokens, you can use [StaticBearerTokenRepository](src/Misc/StaticBearerTokenRepository.php) (Tomaj\NetteApi\Misc\StaticBearerTokenRepository).
239+
For simple use, if you want to use Bearer token authorization with few tokens, you can use [StaticBearerTokenRepository](src/Misc/StaticBearerTokenRepository.php) (Tomaj\NetteApi\Misc\StaticBearerTokenRepository).
240240

241241
```neon
242242
services:
@@ -293,7 +293,7 @@ services:
293293

294294
## Logging
295295

296-
It is good practice to log you api access if you provide valuable information with your API. To enable logging you need to implement class with interface [ApiLoggerInterface](src/Logger/ApiLoggerInterface.php) (Tomaj\NetteApi\Logger\ApiLoggerInterface) and register it as service in *config.neon*. It will be automatically wired and called after execution of all api requests.
296+
It is good practice to log you api access if you provide valuable information with your API. To enable logging you need to implement class with interface [ApiLoggerInterface](src/Logger/ApiLoggerInterface.php) (Tomaj\NetteApi\Logger\ApiLoggerInterface) and register it as service in *config.neon*. It will be automatically wired and called after execution of all API requests.
297297

298298
## CORS Security
299299

UPGRADE.md

+16-10
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
## Upgrade from 1.x to 2.0.0
44

55
### Splitted InputParam to multiple subclasses
6-
InputParam is now abstract class and all types have their own class. Also InputParam is more like Nette Form inputs with fluent API
6+
InputParam is now abstract class and all types have their own classes. Also InputParam is more like Nette Form inputs with fluent API.
77

88
Examples of replacements:
99

10-
Requred get input with available values:
10+
Required GET input with available values:
1111

1212
Old:
1313
```php
@@ -19,7 +19,7 @@ New:
1919
(new GetInputParam('status'))->setRequired()->setAvailableValues(['ok', 'error'])
2020
```
2121

22-
Multiple optional file input:
22+
Multiple optional FILE input:
2323

2424
Old:
2525
```php
@@ -31,14 +31,16 @@ New:
3131
(new FileInputParam('myfile'))->setMulti()
3232
```
3333

34+
For more info about types, see readme section Input Types.
35+
3436
### Removed support for old PHP versions
35-
New version not supported PHP versions 5.6 and 7.0 and also hhvm. Please use it with newer versions of PHP (>7.1)
37+
New version does not support PHP versions 5.6 and 7.0 and also hhvm. Please use it with newer versions of PHP (>7.1)
3638

3739
### Updated dependencies
38-
Version 2.0.0 requires nette packages in version 3.0, so probably you will have to upgrade whole your nette application
40+
Version 2.0.0 requires nette packages in version 3.0, so probably you will have to upgrade whole nette application.
3941

4042
### Typehints
41-
There are some breaking changes because of typehints:
43+
There are some breaking changes because of added typehints:
4244

4345
#### ApiAuthorizationInterface
4446
Add typehints to methods:
@@ -92,6 +94,9 @@ BaseHandler now have few final methods:
9294
- `setupLinkGenerator`
9395
- `createLink`
9496

97+
### Removed class
98+
Class ApiResponse has been removed. Use JsonApiResponse instead.
99+
95100
### Removed params
96101
Parameters $parent and $name have been removed from ApiListingControl. New usage is:
97102
```php
@@ -102,10 +107,10 @@ new ApiListingControl($apiDecider)
102107
Some parameters were strictly typed:
103108
- second parameter in `JsonApiResponse::__construct` (`$payload` formerly known as `$data`) is now `array`
104109
- fifth parameter in `JsonApiResponse::__construct` (`$expiration`) is now `DateTimeInteface` or `null`
105-
- fourth parameter in `InputParam::__construct` (`$availableValues`) is now `array` or `null`
110+
- fourth parameter in `InputParam::__construct` (`$availableValues`, now parameter of method `setAvailableValues()`) is now `array`
106111

107112
### Changed events
108-
Registration of event onClick in ApiListingControl.
113+
Registration of event onClick in ApiListingControl has been changed.
109114
Use:
110115
```php
111116
$apiListing->onClick[] = function ($method, $version, $package, $apiAction) {
@@ -115,5 +120,6 @@ $apiListing->onClick[] = function ($method, $version, $package, $apiAction) {
115120

116121
### Features
117122
With new version of Nette API you can:
118-
- add description for your API handlers, also you can mark some handlers as deprecated and add tags for them.
119-
- add description, default value and example for all your input params
123+
- add description to your API handlers, also you can mark some handlers as deprecated and add tags for them.
124+
- add description, default value and example for all your input params.
125+
- add list of possible outputs which are validate before response is sent to user. If output is not valid, error is sent.

src/ApiDecider.php

-8
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,6 @@ public function enableGlobalPreflight(ApiHandlerInterface $corsHandler = null)
5555
$this->globalPreflightHandler = $corsHandler;
5656
}
5757

58-
/**
59-
* @deprecated use addApi instead
60-
*/
61-
public function addApiHandler(EndpointInterface $endpointIdentifier, ApiHandlerInterface $handler, ApiAuthorizationInterface $apiAuthorization)
62-
{
63-
return $this->addApi($endpointIdentifier, $handler, $apiAuthorization);
64-
}
65-
6658
/**
6759
* Register new api handler
6860
*

0 commit comments

Comments
 (0)