PHPackages                             vinceurag/simplyrest - 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. vinceurag/simplyrest

ActiveProject[API Development](/categories/api)

vinceurag/simplyrest
====================

A micro-framework written in PHP that will help you build RESTful APIs.

v1.0.1(9y ago)61131MITPHP

Since Dec 26Pushed 9y ago2 watchersCompare

[ Source](https://github.com/vinceurag/SimplyREST)[ Packagist](https://packagist.org/packages/vinceurag/simplyrest)[ RSS](/packages/vinceurag-simplyrest/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (2)Used By (1)

SimplyREST
==========

[](#simplyrest)

A micro-framework written in PHP that will help you build RESTful APIs.

Getting Started
---------------

[](#getting-started)

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

### Prerequisites

[](#prerequisites)

Some things that you need

```
MySQL Server
Web Server
Composer

```

### Installing

[](#installing)

Make sure `composer` is installed on your machine and the `$HOME/.composer/vendor/bin` directory is in your $PATH so the `srest` executable can be located by your system.

Download the SimplyREST installer via composer

```
composer global require vinceurag/sr_installer

```

Initialize a new app

```
srest new myapi

```

Verify that your web server and mysql is started.

Modify `config/database.php` with your database details.

```
$db['host'] = 'localhost';
$db['user'] = 'root';
$db['password'] = '';
$db['database'] = 'test_db';

```

Test if it's working. Go to `//SimplyREST/`For example you're using XAMPP and you cloned this project to `htdocs`, you need to go to

```
http://localhost/myapi/

```

You should see something like:

```
{
    "status" : "successful",
    "details" : "framework was installed successfully"
}

```

Play around with the controllers on `/api`

How To Use
----------

[](#how-to-use)

```
DO NOT MODIFY ANYTHING IN THE /core FOLDER AND index.php

```

```
SAMPLE DATABASE SCHEMA IN config/test_db.sql

```

### Controllers

[](#controllers)

Controllers are located under `/api`Every controller MUST extend the SR\_Controller.

This REST server supports the most common 4 HTTP Methods: `GET, POST, PUT, DELETE`.

When creating a function, this should be the format: `HTTPMETHOD_functionname()`. For example, get\_name(). If the user accessed /name using the GET method, this method will be invoked. Else, if the user accessed it via POST method, the post\_name will be invoked.

To send a response, use the function:

```
$this->sendResponse($arrayData, HTTP_Status::HTTP_OK)

```

`$this->sendResponse()` takes in two parameters, the data you want to be the response body (in array) and a status code.

Status codes are defined in `core/HTTP_Status.php`

```
HTTP_OK = 200

HTTP_CREATED = 201

HTTP_NOT_FOUND = 404

HTTP_UNAUTHORIZED = 401

```

To access the POST or PUT json sent to the server, use the function:

```
$anyVariable $this->getJsonData()

```

This function will return the json sent to the server in an array format.

To load the model, use the function:

```
$this->load("model_name")

```

`$model_name` is the class name of your model. You should load the model in your controller's constructor. To use the loaded model, you just need to append the `model_name` to `$this->`. For example, I loaded the model `anothermodel` in the constructor `$this->load_model("anothermodel")`, to access it inside the functions in my controller, I can call `$this->anothermodel->getUser()` assuming there is a getUser() function inside my model.

### Models

[](#models)

Models are located under `/models`Every model MUST extend the SR\_Model.

To make a query to the database, use the function:

```
$this->db->exec("SELECT * FROM tbl_users");

```

If the SQL statement is a `SELECT` statement, this function will return an array of the result (which you can directly send as a response in the controller). Else, this will return a bool.

To `UPDATE` a row, use the function:

```
$this->db->udapte_record($table, $arrayChanges, "id=condition");

```

If a record was successfully updated, it will return a success json.

### Routes

[](#routes)

Routes are the heart and soul of this project. It will determine which class and function will be called.

The structure of the route should always be

```
class_name/function_name/

```

#### Customizing Routes

[](#customizing-routes)

You can customize the routes in the `config/routes.php` folder.

```
$route['/about'] = "test";

```

Here, we are routing `/about` to execute the get\_index() of the Test class.

```
$route['/about/name/:param'] = "test/name";

```

We can also add parameters by putting `:param` in the place wherein we expect a parameter. This route will invoke the get\_name($a) function of Test class, passing any value in place of the `:param` to the function.

```
$route['about/name/:param/age/:param'] = "test/nameage";

```

This project also supports multiple parameters. In this example we passed a name and age in that format. By this route, we tell our REST server to invoke the get\_nameage($name, $age) method in the Test class. Also, passing the all the parameters.

### Libraries

[](#libraries)

Libraries are located under `/libraries`

You should load the needed libraries in the constructor of the controller via the command:

```
$this->load("library_name")

```

#### JSON Web Token Library

[](#json-web-token-library)

The JWT Library can be used to generate a token.

To generate a token:

```
$this->jwt->generate_token($user_id, $arrayPayload)

```

`$user_id` is the unique identifier of the user. `$arrayPayload` is the custom payload you want to add to the token

To check if the user passed a VALID json web token to the authorization header:

```
$this->jwt->check()

```

If it's a valid token, it will return the decoded token and the authorization status ("authorized" or "unauthorized"). Sample response:

```
{
    "consumerKey": "YOUR-CONSUMER-KEY",
    "userId": 1,
    "issuedAt": "11/29/2016 00:47:42 AMNov",
    "data": {
        "name": "New Name",
        "pass": "new_pass"
    },
    "authorization": "authorized"
}

```

Deployment
----------

[](#deployment)

Since some shared hosting does not read directly from the .htaccess, you may want to enter it manually or ask some help from your hosting provider.

Contributing
------------

[](#contributing)

When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.

Authors
-------

[](#authors)

- **Vince Urag** - *Initial work* - [Twitter](https://twitter.com/MrStreetGrid)

See also the list of [contributors](CONTRIBUTORS.md) who participated in this project.

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE) file for details

Acknowledgments
---------------

[](#acknowledgments)

- [JREAM](https://bitbucket.org/JREAM/) - idea for the routing
- [Neuman Vong](https://github.com/luciferous) - JWT Library

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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

Unknown

Total

1

Last Release

3421d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7033d51448a96ee328baa452997e1060dfad46e4661cd47cc0f67d2dc773880a?d=identicon)[vinceurag](/maintainers/vinceurag)

---

Top Contributors

[![vinceurag](https://avatars.githubusercontent.com/u/19531438?v=4)](https://github.com/vinceurag "vinceurag (59 commits)")

### Embed Badge

![Health badge](/badges/vinceurag-simplyrest/health.svg)

```
[![Health](https://phpackages.com/badges/vinceurag-simplyrest/health.svg)](https://phpackages.com/packages/vinceurag-simplyrest)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M475](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M270](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M452](/packages/google-gax)

PHPackages © 2026

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