PHPackages                             dawaa/jacwright-restserver-extended - 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. dawaa/jacwright-restserver-extended

ActiveLibrary[API Development](/categories/api)

dawaa/jacwright-restserver-extended
===================================

An extended version of jacwright/RestServer

1.2.6(8y ago)019PHP

Since Dec 19Pushed 8y ago1 watchersCompare

[ Source](https://github.com/dawaa/jacwright-RestServer-extended)[ Packagist](https://packagist.org/packages/dawaa/jacwright-restserver-extended)[ RSS](/packages/dawaa-jacwright-restserver-extended/feed)WikiDiscussions master Synced 2d ago

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

Jacwright / REST Server (Extended)
==================================

[](#jacwright--rest-server-extended)

The backbone of this project is this repository, [jacwright/RestServer](https://github.com/jacwright/RestServer).

Table of Contents
-----------------

[](#table-of-contents)

- [Supports](#supports)
    - [Request methods](#request-methods)
    - [Adapters](#adapters)
- [Installation](#installation)
    - [.htaccess](#htaccess)
    - [Using composer](#using-composer)
    - [Directly usage](#directly-usage)
- [Configuration](#configuration)
    - [The server](#the-server)
    - [Setting up the database](#setting-up-the-database)
        - [Using composer](#using-composer-1)
        - [Directly usage](#directly-usage-1)
    - [Setting up PHPUnit](#setting-up-phpunit)
- [Whats a Resource?](#whats-a-resource)
- [Looking at a Controller](#looking-at-a-controller)
    - [The init() method](#the-init-method)
    - [A method inside Controller](#a-method-inside-controller)
    - [Method annotations](#method-annotations)
    - [Response structure-checking](#response-structure-checking)
- [Looking at a Model](#looking-at-a-model)
    - [The init() method](#the-init-method-1)
- [Database](#database)
    - [Helpers](#helpers)
    - [Example usage](#example-usage)

---

Supports
--------

[](#supports)

This will tell you what the project currently supports in terms of HTTP request methods available and what types of databases you can use.

#### Request methods

[](#request-methods)

Available methods are

- GET
- POST
- PUT
- DELETE
- PATCH

#### Adapters

[](#adapters)

- MySQLi
- PDO
- PostGreSQL
- Oracle

Installation
------------

[](#installation)

> **NOTE** that you'll see me use ** in the examples below.. This is simply a virtual host set up on my own local machine and I advise you to do the same, but the name could be totally different, of course.

#### .htaccess

[](#htaccess)

> **NOTE** that you might have to tweak with .htaccess to get it right, unless you think e.g. `http://api.local/index.php/users` would be attractive.

If you `$ git clone`'d the project then you'll already have an *.htaccess* in the root of the project.. If you didn't then you would have to add it yourself.. here's how mine look like though..

```
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} !v1/(.*)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* http://%{HTTP_HOST}/v1/ [QSA]
RewriteRule ^v1/(.*)/?$ index.php?segments=$1 [QSA,L]

```

So what it does is that it takes anything and redirects you to `/v1/SEGMENTS_IF_YOU_HAVE_ANY` no matter what. You might want to have your own base url, but for me I would just stick with `v1` for as long as possible since a REST API is not supposed to change that often anyway, if you consider its users.

#### Using Composer

[](#using-composer)

> **NOTE** Make sure that you got Composer installed globally on your system, otherwise check it out **[here](https://getcomposer.org/doc/00-intro.md#globally)** how to install it.

**5 steps**

1. Run `$ composer require dawaa/jacwright-restserver-extended` to download this project into your vendor/ directory.
2. Add ./*config.php* at the root of your project, leave it empty for now.

    - See [Configuration - Setting up the database](#setting-up-the-database) later...
3. Again at the root of your project, add the following to the *./index.php* file to quickly determine if things seems to be working.

    ```
    // index.php
