PHPackages                             k7/nette-rest-route - 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. [API Development](/categories/api)
4. /
5. k7/nette-rest-route

ActiveLibrary[API Development](/categories/api)

k7/nette-rest-route
===================

Rest route for Nette Framework

3.0.0(10y ago)021MITPHPPHP &gt;=5.6.0

Since Mar 31Pushed 10y ago1 watchersCompare

[ Source](https://github.com/keeper7/Nette-RestRoute)[ Packagist](https://packagist.org/packages/k7/nette-rest-route)[ Docs](https://github.com/newPOPE/Nette-RestRoute)[ RSS](/packages/k7-nette-rest-route/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (5)Versions (17)Used By (0)

REST route for [Nette Framework](http://nette.org)
==================================================

[](#rest-route-for-nette-framework)

[![Build Status](https://camo.githubusercontent.com/8836ac8961df3a5c17dc177faa73b30a9985fb915422761cb4cef682529cbbed/68747470733a2f2f7472617669732d63692e6f72672f6e6577504f50452f4e657474652d52657374526f7574652e706e67)](https://travis-ci.org/newPOPE/Nette-RestRoute)

Route automatically maps CRUD to Presenters and actions in the defined module. And creates parameters which are accessible in Presenter.

- format
- id (autodetected)
- associations (an array with associations)
- data (raw data from the request)
- query (an array of items from the query string)

Format detection:
-----------------

[](#format-detection)

Variable `$format` is detected from HTTP header `Accept`. If header is not present Route try detect format from the URL (`.../foo.json`). If no format is in the URL Route use a default format `json`.

Installation:
-------------

[](#installation)

The best way to install Nette-RestRoute is using [Composer](http://getcomposer.org/):

```
$ composer require adamstipak/nette-rest-route
```

Usage:
------

[](#usage)

```
use AdamStipak\RestRoute;

// $router is an instance of Nette\Application\Routers\RouteList

// No parameters needed. Presenter name will be generated.
$router[] = new RestRoute;

// With module.
$router[] = new RestRoute('Api');

// With module and xml as a default format.
$router[] = new RestRoute('Api', 'xml');
```

First parameter is a name of the module where the route will sends an Request. URL prefix will be generated. See examples. ####Examples:

```
NULL      => /
'Api'     => /api/
'My:Api'  => /my/api/
...

```

Second parameter is default format. By default the default format is `json`. RestRoute support only 2 formats:

- json *(default)*
- xml

Examples
--------

[](#examples)

### Read all:

[](#read-all)

**URL:** `/api/users` → `\ApiModule\UsersPresenter::actionReadAll`
**HTTP HEADER Accept:** `application/json`
**Method:** GET
**Request body:** Empty
**Params:**

```
format = json
associations = array(0)
data = ""
query = array(0)

```

> Flag `readAll` was dropped and `Route` automatically generate action `readAll` if no Resource ID was not found in the URL.

---

### Read with resource ID

[](#read-with-resource-id)

**URL:** `/api/users/123` → `\ApiModule\UsersPresenter::actionRead`
**HTTP HEADER Accept:** `application/json`
**Method:** GET
**Request body:** Empty
**Params:**

```
format = json
id = 123
associations = array(0)
data = ""
query = array(0)

```

---

### Query params:

[](#query-params)

**URL:** `/api/users?foo=bar&page=1` → `\ApiModule\UsersPresenter::actionRead`
**HTTP HEADER Accept:** `application/json`
**Method:** GET
**Request body:** Empty
**Params:**

```
format = json
associations = array(0)
data = ""
query = array(
	foo => "bar"
	page => 1
)

```

---

### Create:

[](#create)

**URL:** `/api/users` → `\ApiModule\UsersPresenter::actionCreate`
**HTTP HEADER Accept:** `application/json`
**Method:** POST
**Request body:**

```
{
	"foo": "bar",
	"nested": {
		"foo": "bar"
	}
}
```

**Params:**

```
format = json
associations = array(0)
data = {"foo": "bar", "nested": {"foo": "bar"}}
query = array(0)

```

---

### Update:

[](#update)

**URL:** `/api/users/123` → `\ApiModule\UsersPresenter::actionUpdate`
**HTTP HEADER Accept:** `application/json`
**Method:** PUT
**Request body:**

```
{
	"foo": "bar",
	"nested": {
		"foo": "bar"
	}
}
```

**Params:**

```
format = json
id = 123
associations = array(0)
data = {"foo": "bar", "nested": {"foo": "bar"}}
query = array(0)

```

---

### Partial update:

[](#partial-update)

**URL:** `/api/users/123` → `\ApiModule\UsersPresenter::actionPartialUpdate`
**HTTP HEADER Accept:** `application/json`
**Method:** PATCH
**Request body:**

```
{
	"foo": "bar",
	"nested": {
		"foo": "bar"
	}
}
```

**Params:**

```
format = json
id = 123
associations = array(0)
data = {"foo": "bar", "nested": {"foo": "bar"}}
query = array(0)

```

---

### Delete:

[](#delete)

**URL:** `/api/users/123` → `\ApiModule\UsersPresenter::actionDelete`
**HTTP HEADER Accept:** `application/json`
**Method:** DELETE
**Request body:** Empty
**Params:**

```
format = json
id = 123
associations = array(0)
data = ""
query = array(0)

```

---

### Options:

[](#options)

For more about OPTIONS documentation see [w3.org](http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.2).

**URL:** `/api/users` → `\ApiModule\UsersPresenter::actionOptions`
**HTTP HEADER Accept:** `application/json`
**Method:** OPTIONS
**Request body:** Empty
**Params:**

```
format = json
associations = array(0)
data = ""
query = array(0)

```

---

### Associations:

[](#associations)

Last item (pair) before . is main resource. Everything what is before the last item are associations ([apigee.com](http://apigee.com/about/)).

**URL:** `/api/users/1/comments` → `\ApiModule\CommentsPresenter::actionRead|actionCreate|actionUpdate|actionDelete`
**HTTP HEADER Accept:** `application/json`
**Method:** GET, POST, PUT, DELETE
**Request body:** Empty
**Params:**

```
format = json
associations = array(
	users => 1
)
data = ""
query = array(0)

```

**URL:** `/api/users/123/comments/456` → `\ApiModule\CommentsPresenter::actionRead|actionCreate|actionUpdate|actionDelete`
**HTTP HEADER Accept:** `application/json`
**Method:** GET, POST, PUT, DELETE
**Request body:** Empty
**Params:**

```
format = json
id = 456
associations = array(
	users => 123
)
data = ""
query = array(0)

```

**URL:** `/api/users/1/blogs/2/comments` → `\ApiModule\CommentsPresenter::actionRead|actionCreate|actionUpdate|actionDelete`
**HTTP HEADER Accept:** `application/json`
**Method:** GET, POST, PUT, DELETE
**Request body:** Empty
**Params:**

```
format = json
id = 1
associations = array(
	users => 1
	blogs => 2
)
data = ""
query = array(0)

```

\##Overriding methods PUT, PATCH, DELETE

Methods `PUT`, `PATCH` and `DELETE` can be overriden via:

### HTTP header `X-HTTP-Method-Override`

[](#http-header-x-http-method-override)

Example:

```
X-HTTP-Method-Override:

```

### Query param `__method`

[](#query-param-__method)

Example:

```
?__method=

```

\##Development

RestRoute is developed in [Docker](https://docker.com) container via `docker-compose` command.

Example:

```
$ docker-compose run --rm default install  # install deps via composer
$ docker-compose run --rm default  # runs tests in container
```

Attach to container:

```
$ docker-compose run --rm default bash # runs bash in container and attach tty
```

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 88.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~70 days

Recently: every ~84 days

Total

16

Last Release

3779d ago

Major Versions

1.2.0 → 2.0.02013-09-24

2.6.1 → 3.0.02016-02-17

### Community

Maintainers

![](https://www.gravatar.com/avatar/53d0c48337f92c0b09319f149b189d9e42047924796457488fbff5ae0c4e1a07?d=identicon)[keeper7](/maintainers/keeper7)

---

Top Contributors

[![newPOPE](https://avatars.githubusercontent.com/u/484382?v=4)](https://github.com/newPOPE "newPOPE (91 commits)")[![freezy-sk](https://avatars.githubusercontent.com/u/661637?v=4)](https://github.com/freezy-sk "freezy-sk (4 commits)")[![freezysko](https://avatars.githubusercontent.com/u/661637?v=4)](https://github.com/freezysko "freezysko (4 commits)")[![jsifalda](https://avatars.githubusercontent.com/u/1549390?v=4)](https://github.com/jsifalda "jsifalda (2 commits)")[![fabiancz](https://avatars.githubusercontent.com/u/1045330?v=4)](https://github.com/fabiancz "fabiancz (1 commits)")[![klimesf](https://avatars.githubusercontent.com/u/5357636?v=4)](https://github.com/klimesf "klimesf (1 commits)")

---

Tags

netterouting

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/k7-nette-rest-route/health.svg)

```
[![Health](https://phpackages.com/badges/k7-nette-rest-route/health.svg)](https://phpackages.com/packages/k7-nette-rest-route)
```

###  Alternatives

[nette/forms

📝 Nette Forms: generating, validating and processing secure forms in PHP. Handy API, fully customizable, server &amp; client side validation and mature design.

52913.5M483](/packages/nette-forms)[nette/application

🏆 Nette Application: a full-stack component-based MVC kernel for PHP that helps you write powerful and modern web applications. Write less, have cleaner code and your work will bring you joy.

44815.8M1.1k](/packages/nette-application)[tomaj/nette-api

Nette api

36269.8k6](/packages/tomaj-nette-api)[contributte/translation

Symfony/Translation integration for Nette Framework.

771.8M49](/packages/contributte-translation)[adamstipak/nette-rest-route

Rest route for Nette Framework

68152.3k](/packages/adamstipak-nette-rest-route)[dotblue/nette-webimages

On-the-fly generated web images for your Nette app

262.1k](/packages/dotblue-nette-webimages)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
