PHPackages                             isigar/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. isigar/restful

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

isigar/restful
==============

Nette REST API bundle

1.2(7y ago)017BSD-3-ClausePHPPHP &gt;= 5.3.0

Since Mar 12Pushed 7y ago1 watchersCompare

[ Source](https://github.com/Isigar/Restful)[ Packagist](https://packagist.org/packages/isigar/restful)[ Docs](http://www.drahak.eu)[ RSS](/packages/isigar-restful/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (14)Versions (4)Used By (0)

Nette REST API
==============

[](#nette-rest-api)

[![Build Status](https://camo.githubusercontent.com/a09c31818830e81d5feca23b771946870b068f7d5b5779f9e9a8803fddd897d9/68747470733a2f2f7472617669732d63692e6f72672f64726168616b2f5265737466756c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/drahak/Restful)

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 register the extension by adding this code to `bootstrap.php` (before creating container):

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

or register it in `config.neon`:

```
extensions:
  restful: Drahak\Restful\DI\RestfulExtension
```

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:
		generateAtStart: FALSE
		prefix: resources
		module: 'RestApi'
		autoGenerated: TRUE
		panel: TRUE
	mappers:
		myMapper:
			contentType: 'multipart/form-data'
			class:  \App\MyMapper
	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.generateAtStart`: generating routes at start of Router (**only for auto generated routes and if is Router set over config.neon**)
- `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
- `mappers`: replace existing mappers or add new mappers for different content-types
- `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)

```
