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
Copy file name to clipboardExpand all lines: README.md
+19-19
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@
12
12
13
13
## Why Nette-Api
14
14
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.
16
16
17
17
## Installation
18
18
@@ -21,7 +21,7 @@ This library requires PHP 7.1 or later.
21
21
Recommended installation method is via Composer:
22
22
23
23
```bash
24
-
$ composer require tomaj/nette-api
24
+
composer require tomaj/nette-api
25
25
```
26
26
27
27
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][].
33
33
34
34
## How Nette-API works
35
35
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:
37
37
38
38
```neon
39
39
application:
@@ -47,7 +47,7 @@ And add route to you RouterFactory:
47
47
$router[] = new Route('/api/v<version>/<package>[/<apiAction>][/<params>]', 'Api:Api:default');
48
48
```
49
49
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*:
51
51
52
52
```neon
53
53
services:
@@ -67,13 +67,13 @@ This example will prepare these API calls:
67
67
2.`http://yourapp/api/v1/users/send-email` - available via POST
68
68
69
69
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:
71
71
72
72
1. App\MyApi\v1\Handlers\UsersListingHandler
73
73
2. App\MyApi\v1\Handlers\SendEmailHandler
74
74
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.
77
77
78
78
```php
79
79
namespace App\MyApi\v1\Handlers;
@@ -108,13 +108,13 @@ This simple handler is using *UsersRepository* that was created by Nette Contain
108
108
## Advanced use (with Fractal)
109
109
110
110
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()`.
112
112
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.
114
114
115
115
Example with fractal:
116
116
117
-
1. You will need Formater
117
+
1. You will need Transformer
118
118
119
119
```php
120
120
namespace App\MyApi\v1\Transformers;
@@ -165,13 +165,13 @@ class UsersListingHandler extends Basehandler
165
165
}
166
166
```
167
167
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.
169
169
170
170
[Fractal]: http://fractal.thephpleague.com/
171
171
172
172
## Endpoint inputs
173
173
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.
175
175
176
176
Example with user detail:
177
177
@@ -217,26 +217,26 @@ class UsersDetailHandler extends Basehandler
217
217
218
218
## Input Types
219
219
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.
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*.
238
238
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).
240
240
241
241
```neon
242
242
services:
@@ -293,7 +293,7 @@ services:
293
293
294
294
## Logging
295
295
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.
0 commit comments