PHPackages                             erwin32/drahak-restful - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. erwin32/drahak-restful

ActiveLibrary[HTTP &amp; Networking](/categories/http)

erwin32/drahak-restful
======================

Nette REST API bundle

v1.0(11y ago)028BSD-3-ClausePHPPHP &gt;= 5.3.0

Since Jan 6Pushed 11y ago1 watchersCompare

[ Source](https://github.com/Erwin32/drahakRestful)[ Packagist](https://packagist.org/packages/erwin32/drahak-restful)[ Docs](http://www.drahak.eu)[ RSS](/packages/erwin32-drahak-restful/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

Nette REST API by Drahak
========================

[](#nette-rest-api-by-drahak)

This repository is being developed.

### Content

[](#content)

- [Requirements](#requirements)
- [Installation &amp; setup](#installation--setup)
- [Neon configuration](#neon-configuration)
- [Sample usage](#sample-usage)
- [Simple CRUD resources](#simple-crud-resources)
- [Accessing input data](#accessing-input-data)
- [Input data validation](#input-data-validation)
- [Error presenter](#error-presenter)
- [Security &amp; authentication](#security--authentication)
- [Secure your resources with OAuth2](#secure-your-resources-with-oauth2)
- [JSONP support](#jsonp-support)
- [Utilities that make life better](#utilities-that-make-life-better)

Requirements
------------

[](#requirements)

Drahak/Restful requires PHP version 5.3.0 or higher. The only production dependency is [Nette framework 2.0.x](http://www.nette.org). The Restful also works well with my Drahak\\OAuth2 provider (see [Secure your resources with OAuth2](#secure-your-resources-with-oauth2))

Installation &amp; setup
------------------------

[](#installation--setup)

The easiest way is to use [Composer](http://doc.nette.org/en/composer)

```
$ composer require drahak/restful:@dev

```

Then add following code to your app bootstrap file before creating container:

```
Drahak\Restful\DI\RestfulExtension::install($configurator);
```

Neon configuration
------------------

[](#neon-configuration)

You can configure Drahak\\Restful library in config.neon in section `restful`:

```
restful:
	convention: 'snake_case'
	cacheDir: '%tempDir%/cache'
	jsonpKey: 'jsonp'
	prettyPrintKey: 'pretty'
	routes:
		prefix: resources
		module: 'RestApi'
		autoGenerated: TRUE
		panel: TRUE
	security:
		privateKey: 'my-secret-api-key'
		requestTimeKey: 'timestamp'
		requestTimeout: 300
```

- `cacheDir`: not much to say, just directory where to store cache
- `jsonpKey`: sets query parameter name, which enables [JSONP envelope mode](#jsonp-support). Set this to FALSE if you wish to disable it.
- `prettyPrintKey`: API prints every resource with pretty print by default. You can use this query parameter to disable it
- `convention`: resource array keys conventions. Currently supported 3 values: `snake_case`, `camelCase` &amp; `PascalCase` which automatically converts resource array keys. You can write your own converter. Just implement `Drahak\Restful\Resource\IConverter` interface and tag your service with `restful.converter`.
- `routes.prefix`: mask prefix to resource routes (**only for auto generated routes**)
- `routes.module`: default module to resource routes (**only for auto generated routes**)
- `routes.autoGenerated`: if `TRUE` the library auto generate resource routes from Presenter action method annotations (see below)
- `routes.panel`: if `TRUE` the resource routes panel will appear in your nette debug bar
- `security.privateKey`: private key to hash secured requests
- `security.requestTimeKey`: key in request body, where to find request timestamp (see below - [Security &amp; authentication](#security--authentication))
- `security.requestTimeout`: maximal request timestamp age

**Tip:** Use gzip compression for your resources. You can enable it simply in neon:

```
php:
    zlib.output_compression: yes
```

#### Resource routes panel

[](#resource-routes-panel)

It is enabled by default but you can disable it by setting `restful.routes.panel` to `FALSE`. This panel show you all REST API resources routes (exactly all routes in default route list which implements `IResourceRouter` interface). This is useful e.g. for developers who develop client application, so they have all API resource routes in one place. [![REST API resource routes panel](https://camo.githubusercontent.com/633ca13b69b1235b5d3f61561defeecb265199b30bafc907346bbeed17965733/687474703a2f2f66696c65732e64726168616b2e65752f7265737466756c2d726f757465732d70616e656c2e706e67 "REST API resource routes panel")](https://camo.githubusercontent.com/633ca13b69b1235b5d3f61561defeecb265199b30bafc907346bbeed17965733/687474703a2f2f66696c65732e64726168616b2e65752f7265737466756c2d726f757465732d70616e656c2e706e67)

Sample usage
------------

[](#sample-usage)

```
