Skip to content

Commit

Permalink
Readme: mention extension + examples
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Dec 26, 2022
1 parent 8bf9ca0 commit 6963e46
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions .docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
+ [Using annotation](#using-annotation)
+ [Using Nette Router](#using-nette-router)
+ [Api documentation](#api-documentation)
- [Examples](#examples)

## Installation

Expand All @@ -18,17 +19,36 @@ composer require contributte/api-router

## Usage

### Configure

At first register compiler extension.

```neon
extensions:
apiRouter: Contributte\ApiRouter\DI\ApiRouterExtension
```

Don't forget to register your controller/presenter/endpoint classes.

```neon
services:
- App\Controllers\LoginController
- App\Controllers\PingController
```

### Using annotation

Example of used annotations. Don't forget to import `Contributte\ApiRouter\ApiRoute`, it's required by [doctrine/annotations](https://github.com/doctrine/annotations).

```php
namespace App\ResourcesModule\Presenters;

use Nette;
use Nette\Application\UI\Presenter;
use Contributte\ApiRouter\ApiRoute;

/**
* API for managing users
*
*
* @ApiRoute(
* "/api-router/api/users[/<id>]",
* parameters={
Expand All @@ -41,21 +61,20 @@ use Contributte\ApiRouter\ApiRoute;
* presenter="Resources:Users"
* )
*/
class UsersPresenter extends Nette\Application\UI\Presenter
class UsersController extends Presenter
{

/**
* Get user detail
*
*
* @ApiRoute(
* "/api-router/api/users/<id>[/<foo>-<bar>]",
* parameters={
* "id"={
* "requirement": "\d+"
* }
* },
* method="GET",
* }
* method="GET"
* )
*/
public function actionRead($id, $foo = NULL, $bar = NULL)
Expand Down Expand Up @@ -144,3 +163,9 @@ class RouterFactory

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!

## Examples

We've made a few skeleton with preconfigured `contributte/api-router`.

https://github.com/contributte/api-router-skeleton

0 comments on commit 6963e46

Please sign in to comment.