PHPackages                             zulfajuniadi/php-rest-server - 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. zulfajuniadi/php-rest-server

ActiveLibrary[API Development](/categories/api)

zulfajuniadi/php-rest-server
============================

Plug and Play PHP Rest Server. Just download and run. Supports Backbone.js out of the box.

v1.0.1(12y ago)12392MITPHPPHP &gt;=5.3.0

Since Jan 19Pushed 12y ago3 watchersCompare

[ Source](https://github.com/zulfajuniadi/PHP-REST-Server)[ Packagist](https://packagist.org/packages/zulfajuniadi/php-rest-server)[ RSS](/packages/zulfajuniadi-php-rest-server/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (3)Versions (3)Used By (0)

PHP REST Server
===============

[](#php-rest-server)

You can read the introduction on my [blog](http://zulfait.blogspot.com/2014/01/php-rest-server.html). ##Features

1. Automatically generated resources (tables and table structure) based on incomming data.
2. Routes are automatically generated from the database. Apart from the initial config.php edit, you won't need to modify the code.
3. Supports multiple databases MySQL 5+ SQLite 3.6.19+ PostgreSQL 8+ CUBRUD.
4. Can be accessed in subdirectories (Does not *have* to be located on a different vhost / webroot)
5. Simple ACL System
6. Supports where, limit, order queries
7. Pure JSON API Server. User does not need to use the `emulate_http` in Backbone.js or other similar front-end frameworks
8. Lightweight. Response around 10 - 20 ms per request under untweaked PHP.

\##Installation

1. Install [Composer](http://getcomposer.org/doc/00-intro.md#installation-nix).
2. Create a new project by running: `composer create-project zulfajuniadi/php-rest-server your_directory`
3. Alternatively you can download and extract / clone this repo into your htdocs directory then run `composer install --prefer-dist --no-dev`
4. Change the configs in config.php.default and rename it to config.php.
5. Go To:  to make sure everything is ok. The response should be something like this : `{"error":false,"data":"OK","status":200}`.

\##Usage

1. Go To:  to manage your Api server.
2. Create new package by going to http://\[installationpath\]/manage.
3. Once created, the routes under http://\[installationpath\]/\[packagename\]/\[resourcename\] will be activated
4. \[resourcename\] will be automatically generated for you.

\##Routes

1. **List Records** &gt;&gt; (GET) http://\[installationpath\]/\[packagename\]/\[tableName\]
2. **Get One** &gt;&gt; (GET) http://\[installationpath\]/\[packagename\]/\[tableName\]/\[id\]
3. **Create New** &gt;&gt; (POST) http://\[installationpath\]/\[packagename\]/\[tableName\]
4. **Update** &gt;&gt; (PUT) http://\[installationpath\]/\[packagename\]/\[tableName\]/\[id\]
5. **Delete** &gt;&gt; (DELETE) http://\[installationpath\]/\[packagename\]/\[tableName\]/\[id\]

Example

Let's say you create an application (package) called 'uberpackage' and you want to retrieve all users. The request should be: `http://api.uberapp.com/uberapp/users`

*List Records is subject to the default limit as in the Querying::order section below.*

\##Querying

Queries are appended as query strings to the List Records (GET) request.

\###Where

Key : `where`

Example : [http://api.uberapp.com/uberapp/users?where=\[\["id","&gt;",23\],\["name","like","%adam"\]\]](http://api.uberapp.com/uberapp/users?where=%5B%5B%22id%22,%22%3E%22,23%5D,%5B%22name%22,%22like%22,%22%adam%22%5D%5D)

Generates : `select all from users where id > 23 and name like '%adam';`

*Right now only 'and' is supported*

\###Order

Key : `order`

Example : [http://api.uberapp.com/uberapp/users?order=\[\["age","desc"\],\["name","asc"\]\]](http://api.uberapp.com/uberapp/users?order=%5B%5B%22age%22,%22desc%22%5D,%5B%22name%22,%22asc%22%5D%5D)

Generates : `select all from users order by age desc, name asc;`

*Note that if you did not pass the second parameter in an order array, it will default to asc. The following syntax is valid*

[http://api.uberapp.com/uberapp/users?order=\[\["age"\]\]](http://api.uberapp.com/uberapp/users?order=%5B%5B%22age%22%5D%5D)

Generates : `select all from users order by age asc;`

\###Limit

Key : `limit`

Params : \[$start,$length\]

Example : [http://api.uberapp.com/uberapp/users?limit=\[0,25\]](http://api.uberapp.com/uberapp/users?limit=%5B0,25%5D)

Generates : `select all from users limit 0, 25;`

*By default, all queries will return only 25 rows, you can change the default limit in config.php $config\['default\_sql\_limit'\] variable*

\###Chained

Queries can be chained as per example below:

Example : [http://api.uberapp.com/uberapp/users?where=\[\["age","&gt;",18\]\]&amp;order=\[\["age","desc"\],\["name"\]\]&amp;limit=\[0,50\]](http://api.uberapp.com/uberapp/users?where=%5B%5B%22age%22,%22%3E%22,18%5D%5D&order=%5B%5B%22age%22,%22desc%22%5D,%5B%22name%22%5D%5D&limit=%5B0,50%5D)

Generates : `select * from users where age > 18 order by age desc, name asc limit 0, 50;`

\##Access Control List (ACL)

This REST service offers very simple ACL system where you can set ACL per package level. You can define whether any user are able to list (and query), create, update or remove a record in any combinations. You can also disable the whole package by unchecking the 'Enabled' checkbox in /manage.

\##List of HTTP Responses

- 200 : (OK) Request was successfully performed
- 201 : (Created) A new entry was created (During the POST method)
- 400 : (Bad Request) Either the package has not yet been created, or the package is marked disabled or the method is disabled. (View ACL Section).
- 403 : (Forbidden) The client end did not send the authentication token (Auth-Token) inside the header or the Auth-Token is invalid.
- 404 : (Not Found) The record does not exist. May happen during the Get (GET:/packageName/resourceName/id) One request or Update (PUT:/packageName/resourceName/id) request
- 500 : (Server Error) PHP Farted. Shouldn't Happen. Check Server Logs.
- 503 : (Service Unavailable) For rate limiting.

\##Data Structure

The server responds in the following data format:

```
{
	"error" : false,
	"data" : [],
	"status" : 200
}
```

\##Rate Limiting

You can set a limit on the number of request a user can make. The requests are set per package, per user, per hour. Upon hitting the limit, the REST Service will return a 503 Service Unavailable HTTP Error. Refer to the response headers `Api-Utilization` and `Api-Limit` To view the utilized requests in the current hour and the limit set on the package respectivly.

\##Authentication Token

A token can be generated via the management page. Once generated and tagged to a resource. All request with invalid or missing Auth-Token header, will directly return a 403 Forbidden HTTP Error.

\###Sample Backbone Auth Token Implementation

The below example demonstrates usage of the 'Auth-Token' header.

```
var _sync = Backbone.sync;
Backbone.sync = function(method, model, options) {
	options.beforeSend = function(xhr) {
		xhr.setRequestHeader('Auth-Token' , [generated_token]);
	}
	_sync.call(this,method,model,options);
}
```

\##Example Usage

View the `templates/_manage.html` and `js/manage.js` to view API usage with `Backbone.js`

\##Todos

1. Auto sync (Client data to be persistant on client side, can sync automatically from the server when there are new data)

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~6 days

Total

2

Last Release

4539d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/207807?v=4)[Zulfa Juniadi](/maintainers/zulfajuniadi)[@zulfajuniadi](https://github.com/zulfajuniadi)

---

Top Contributors

[![zulfajuniadi](https://avatars.githubusercontent.com/u/207807?v=4)](https://github.com/zulfajuniadi "zulfajuniadi (48 commits)")

### Embed Badge

![Health badge](/badges/zulfajuniadi-php-rest-server/health.svg)

```
[![Health](https://phpackages.com/badges/zulfajuniadi-php-rest-server/health.svg)](https://phpackages.com/packages/zulfajuniadi-php-rest-server)
```

###  Alternatives

[showdoc/showdoc

ShowDoc is a tool greatly applicable for an IT team to share documents online

12.8k7.1k](/packages/showdoc-showdoc)[brandembassy/slim-nette-extension

19198.2k](/packages/brandembassy-slim-nette-extension)[oat-sa/tao-core

TAO core extension

66140.1k108](/packages/oat-sa-tao-core)[b13/slimphp-bridge

Provides a middleware for registering Slim PHP applications within TYPO3 Frontend Sites

2048.8k1](/packages/b13-slimphp-bridge)

PHPackages © 2026

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