-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf24af4
commit 73b113f
Showing
12 changed files
with
204 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
# ApiRouter | ||
|
||
RESTful Router for your Apis in Nette Framework - created either directly or via annotation | ||
|
||
## Installation | ||
|
||
ApiRouter is available on composer: | ||
|
||
``` | ||
composer require contributte/api-router | ||
``` | ||
|
||
## Usage | ||
|
||
### Using annotation | ||
|
||
```php | ||
namespace App\ResourcesModule\Presenters; | ||
|
||
use Nette; | ||
use Contributte\ApiRouter\ApiRoute; | ||
|
||
/** | ||
* API for managing users | ||
* | ||
* @ApiRoute( | ||
* "/api-router/api/users[/<id>]", | ||
* parameters={ | ||
* "id"={ | ||
* "requirement": "\d+", | ||
* "default": 10 | ||
* } | ||
* }, | ||
* priority=1, | ||
* presenter="Resources:Users" | ||
* ) | ||
*/ | ||
class UsersPresenter extends Nette\Application\UI\Presenter | ||
{ | ||
|
||
/** | ||
* Get user detail | ||
* | ||
* @ApiRoute( | ||
* "/api-router/api/users/<id>[/<foo>-<bar>]", | ||
* parameters={ | ||
* "id"={ | ||
* "requirement": "\d+" | ||
* } | ||
* }, | ||
* method="GET", | ||
* } | ||
* ) | ||
*/ | ||
public function actionRead($id, $foo = NULL, $bar = NULL) | ||
{ | ||
$this->sendJson(['id' => $id, 'foo' => $foo, 'bar' => $bar]); | ||
} | ||
|
||
|
||
public function actionUpdate($id) | ||
{ | ||
$this->sendJson(['id' => $id]); | ||
} | ||
|
||
|
||
public function actionDelete($id) | ||
{ | ||
$this->sendJson(['id' => $id]); | ||
} | ||
} | ||
``` | ||
|
||
Now 3 routes will be created (well, 2, but the one accepts both PUT and DELETE method). | ||
|
||
If you don't want to create route with DELETE method, simply remove the `UsersPresenter::actionDelete()` method. | ||
|
||
### Using Nette Router | ||
|
||
```php | ||
namespace App; | ||
|
||
use Nette; | ||
use Nette\Application\Routers\RouteList; | ||
use Nette\Application\Routers\Route; | ||
use Contributte\ApiRouter\ApiRoute; | ||
|
||
class RouterFactory | ||
{ | ||
|
||
/** | ||
* @return Nette\Application\IRouter | ||
*/ | ||
public function createRouter() | ||
{ | ||
$router = new RouteList; | ||
|
||
/** | ||
* Simple route with matching (only if methods below exist): | ||
* GET => UsersPresenter::actionRead() | ||
* POST => UsersPresenter::actionCreate() | ||
* PUT => UsersPresenter::actionUpdate() | ||
* DELETE => UsersPresenter::actionDelete() | ||
*/ | ||
$router[] = new ApiRoute('/hello', 'Users'); | ||
|
||
/** | ||
* Custom matching: | ||
* GET => UsersPresenter::actionSuperRead() | ||
* POST => UsersPresenter::actionCreate() | ||
*/ | ||
$router[] = new ApiRoute('/hello', 'ApiRouter', [ | ||
'methods' => ['GET' => 'superRead', 'POST'] | ||
]); | ||
|
||
$router[] = new ApiRoute('/api-router/api/users[/<id>]', 'Resources:Users', [ | ||
'parameters' => [ | ||
'id' => ['requirement' => '\d+', 'default' => 10] | ||
], | ||
'priority' => 1 | ||
]); | ||
|
||
$router[] = new ApiRoute('/api-router/api/users/<id>[/<foo>-<bar>]', 'Resources:Users', [ | ||
'parameters' => [ | ||
'id' => ['requirement' => '\d+'] | ||
], | ||
'priority' => 1 | ||
]); | ||
|
||
$router[] = new Route('<presenter>/<action>', 'Homepage:default'); | ||
|
||
return $router; | ||
} | ||
} | ||
``` | ||
|
||
### Api documentation | ||
|
||
There is another extension for Nette which works pretty well with ApiRouter: [ApiDocu](https://github.com/contributte/api-docu). | ||
ApiDocu generates awesome api documentation from your RESTful routes. It can also show you documentation in application runtime! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,147 +1,49 @@ | ||
[](https://travis-ci.org/ublaboo/api-router) | ||
[](https://scrutinizer-ci.com/g/ublaboo/api-router/?branch=master) | ||
[](https://packagist.org/packages/ublaboo/api-router) | ||
[](https://packagist.org/packages/ublaboo/api-router) | ||
[](https://packagist.org/packages/ublaboo/api-router) | ||
[](https://gitter.im/ublaboo/help) | ||
# RabbitMQ | ||
|
||
# ApiRouter | ||
Ultra easy-to-use [`RabbitMQ`](https://www.rabbitmq.com/) implementation for [`Nette Framework`](https://github.com/nette/). | ||
|
||
RESTful Router for your Apis in Nette Framework - created either directly or via annotation | ||
[](https://travis-ci.org/contributte/api-router) | ||
[](https://coveralls.io/r/contributte/api-router) | ||
[](https://packagist.org/packages/contributte/api-router) | ||
[](https://packagist.org/packages/contributte/api-router) | ||
[](https://packagist.org/packages/contributte/api-router) | ||
[](https://packagist.org/packages/contributte/api-router) | ||
[](https://github.com/phpstan/phpstan) | ||
|
||
## Installation | ||
 | ||
|
||
ApiRouter is available on composer: | ||
## Discussion / Help | ||
|
||
``` | ||
composer require ublaboo/api-router | ||
``` | ||
[](http://bit.ly/ctteg) | ||
|
||
## Usage | ||
## Documentation | ||
|
||
### Using annotation | ||
- [Installation](.docs/README.md#installation) | ||
- [Usage](.docs/README.md#usage) | ||
- [Using annotation](.docs/README.md#using-annotation) | ||
- [Using Nette Router](.docs/README.md#using-nette-router) | ||
- [Api documentation](.docs/README.md#api-documentation) | ||
|
||
```php | ||
namespace App\ResourcesModule\Presenters; | ||
## Versions | ||
|
||
use Nette; | ||
use Ublaboo\ApiRouter\ApiRoute; | ||
| State | Version | Branch | Nette | PHP | | ||
|--------|--------------|----------|--------|---------| | ||
| stable | `^4.0.0` | `master` | `3.0+` | `^7.1` | | ||
|
||
/** | ||
* API for managing users | ||
* | ||
* @ApiRoute( | ||
* "/api-router/api/users[/<id>]", | ||
* parameters={ | ||
* "id"={ | ||
* "requirement": "\d+", | ||
* "default": 10 | ||
* } | ||
* }, | ||
* priority=1, | ||
* presenter="Resources:Users" | ||
* ) | ||
*/ | ||
class UsersPresenter extends Nette\Application\UI\Presenter | ||
{ | ||
## Maintainers | ||
|
||
/** | ||
* Get user detail | ||
* | ||
* @ApiRoute( | ||
* "/api-router/api/users/<id>[/<foo>-<bar>]", | ||
* parameters={ | ||
* "id"={ | ||
* "requirement": "\d+" | ||
* } | ||
* }, | ||
* method="GET", | ||
* } | ||
* ) | ||
*/ | ||
public function actionRead($id, $foo = NULL, $bar = NULL) | ||
{ | ||
$this->sendJson(['id' => $id, 'foo' => $foo, 'bar' => $bar]); | ||
} | ||
<table> | ||
<tbody> | ||
<tr> | ||
<td align="center"> | ||
<a href="https://github.com/paveljanda"> | ||
<img width="150" height="150" src="https://avatars0.githubusercontent.com/u/1488874?s=150&v=4"> | ||
</a> | ||
</br> | ||
<a href="https://github.com/paveljanda">Pavel Janda</a> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
|
||
public function actionUpdate($id) | ||
{ | ||
$this->sendJson(['id' => $id]); | ||
} | ||
|
||
|
||
public function actionDelete($id) | ||
{ | ||
$this->sendJson(['id' => $id]); | ||
} | ||
} | ||
``` | ||
|
||
Now 3 routes will be created (well, 2, but the one accepts both PUT and DELETE method). | ||
|
||
If you don't want to create route with DELETE method, simply remove the `UsersPresenter::actionDelete()` method. | ||
|
||
### Using Nette Router | ||
|
||
```php | ||
namespace App; | ||
|
||
use Nette; | ||
use Nette\Application\Routers\RouteList; | ||
use Nette\Application\Routers\Route; | ||
use Ublaboo\ApiRouter\ApiRoute; | ||
|
||
class RouterFactory | ||
{ | ||
|
||
/** | ||
* @return Nette\Application\IRouter | ||
*/ | ||
public function createRouter() | ||
{ | ||
$router = new RouteList; | ||
|
||
/** | ||
* Simple route with matching (only if methods below exist): | ||
* GET => UsersPresenter::actionRead() | ||
* POST => UsersPresenter::actionCreate() | ||
* PUT => UsersPresenter::actionUpdate() | ||
* DELETE => UsersPresenter::actionDelete() | ||
*/ | ||
$router[] = new ApiRoute('/hello', 'Users'); | ||
|
||
/** | ||
* Custom matching: | ||
* GET => UsersPresenter::actionSuperRead() | ||
* POST => UsersPresenter::actionCreate() | ||
*/ | ||
$router[] = new ApiRoute('/hello', 'ApiRouter', [ | ||
'methods' => ['GET' => 'superRead', 'POST'] | ||
]); | ||
|
||
$router[] = new ApiRoute('/api-router/api/users[/<id>]', 'Resources:Users', [ | ||
'parameters' => [ | ||
'id' => ['requirement' => '\d+', 'default' => 10] | ||
], | ||
'priority' => 1 | ||
]); | ||
|
||
$router[] = new ApiRoute('/api-router/api/users/<id>[/<foo>-<bar>]', 'Resources:Users', [ | ||
'parameters' => [ | ||
'id' => ['requirement' => '\d+'] | ||
], | ||
'priority' => 1 | ||
]); | ||
|
||
$router[] = new Route('<presenter>/<action>', 'Homepage:default'); | ||
|
||
return $router; | ||
} | ||
} | ||
``` | ||
|
||
### Api documentation | ||
|
||
There is another extension for Nette which works pretty well with ApiRouter: [ApiDocu](https://github.com/contributte/api-docu). | ||
ApiDocu generates awesome api documentation from your RESTful routes. It can also show you documentation in application runtime! | ||
Thank you for testing, reporting and contributing. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,7 @@ | |
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2016 ublaboo <[email protected]> | ||
* @author Pavel Janda <[email protected]> | ||
* @package Ublaboo | ||
*/ | ||
|
||
namespace Ublaboo\ApiRouter; | ||
namespace Contributte\ApiRouter; | ||
|
||
use Nette; | ||
use Nette\Application\Request; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,16 +2,10 @@ | |
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2016 ublaboo <[email protected]> | ||
* @author Pavel Janda <[email protected]> | ||
* @package Ublaboo | ||
*/ | ||
|
||
namespace Ublaboo\ApiRouter; | ||
namespace Contributte\ApiRouter; | ||
|
||
use Doctrine\Common\Annotations\Annotation\Enum; | ||
use Ublaboo\ApiRouter\Exception\ApiRouteWrongPropertyException; | ||
use Contributte\ApiRouter\Exception\ApiRouteWrongPropertyException; | ||
|
||
abstract class ApiRouteSpec | ||
{ | ||
|
Oops, something went wrong.