Skip to content

Commit

Permalink
ublaboo -> contributte
Browse files Browse the repository at this point in the history
  • Loading branch information
paveljanda committed May 3, 2020
1 parent cf24af4 commit 73b113f
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 186 deletions.
140 changes: 140 additions & 0 deletions .docs/README.md
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!
172 changes: 37 additions & 135 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,147 +1,49 @@
[![Build Status](https://travis-ci.org/ublaboo/api-router.svg?branch=master)](https://travis-ci.org/ublaboo/api-router)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/ublaboo/api-router/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/ublaboo/api-router/?branch=master)
[![Latest Stable Version](https://poser.pugx.org/ublaboo/api-router/v/stable)](https://packagist.org/packages/ublaboo/api-router)
[![License](https://poser.pugx.org/ublaboo/api-router/license)](https://packagist.org/packages/ublaboo/api-router)
[![Total Downloads](https://poser.pugx.org/ublaboo/api-router/downloads)](https://packagist.org/packages/ublaboo/api-router)
[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](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
[![Build Status](https://img.shields.io/travis/contributte/api-router.svg?style=flat-square)](https://travis-ci.org/contributte/api-router)
[![Code coverage](https://img.shields.io/coveralls/contributte/api-router.svg?style=flat-square)](https://coveralls.io/r/contributte/api-router)
[![Licence](https://img.shields.io/packagist/l/contributte/api-router.svg?style=flat-square)](https://packagist.org/packages/contributte/api-router)
[![Downloads this Month](https://img.shields.io/packagist/dm/contributte/api-router.svg?style=flat-square)](https://packagist.org/packages/contributte/api-router)
[![Downloads total](https://img.shields.io/packagist/dt/contributte/api-router.svg?style=flat-square)](https://packagist.org/packages/contributte/api-router)
[![Latest stable](https://img.shields.io/packagist/v/contributte/api-router.svg?style=flat-square)](https://packagist.org/packages/contributte/api-router)
[![PHPStan](https://img.shields.io/badge/PHPStan-enabled-brightgreen.svg?style=flat-square)](https://github.com/phpstan/phpstan)

## Installation
![](https://github.com/contributte/api-router/blob/master/.docs/assets/console.png "Console")

ApiRouter is available on composer:
## Discussion / Help

```
composer require ublaboo/api-router
```
[![Join the chat](https://img.shields.io/gitter/room/contributte/contributte.svg?style=flat-square)](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.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "ublaboo/api-router",
"name": "contributte/api-router",
"type": "library",
"description": "RESTful Router for your Apis in Nette Framework - created either directly or via annotation",
"keywords": ["rest", "api", "routes", "nette", "router", "restapi", "restrouter", "routing", "route"],
"homepage": "https://ublaboo.org/api-router",
"homepage": "https://github.com/contributte/api-router",
"license": ["MIT"],
"support": {
"issues": "https://github.com/ublaboo/api-router/issues"
"issues": "https://github.com/contributte/api-router/issues"
},
"authors": [
{
Expand All @@ -16,12 +16,12 @@
],
"autoload": {
"psr-4": {
"Ublaboo\\ApiRouter\\": "src/"
"Contributte\\ApiRouter\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Ublaboo\\ApiRouter\\Tests\\": "tests"
"Contributte\\ApiRouter\\Tests\\": "tests"
}
},
"require": {
Expand Down
8 changes: 1 addition & 7 deletions src/ApiRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 2 additions & 8 deletions src/ApiRouteSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Loading

0 comments on commit 73b113f

Please sign in to comment.