Easy Rest Server

Thank you for purchasing my script. If you have any questions that are beyond the scope of this help file, please feel free to email via my user page contact form here. Thanks so much!

myRestServer is an easy to use REST Server, packed in one file, ready to interact with your data.

Main Features:




To Start your own API just make a directory or subdomain ie( or and put the included files:


go to or

You'll see a 404 error

This happen because we don't make or call any controller

try or

Now you can see all info related to your REST server.

debug mode

You're almost ready to go!

MyRestServer is bundled with lot of options to help you to build fast and awesome API's:

Inside myRestServer.php:

    // myRestServer version [just for internal use]
    const VERSION = '1.0';

    // switch production / debug
    const PRODUCTION = true;

    // enable production mode on query string by calling:
    const OVERWRITE_PRODUCTION = true;

    // simple string protection to disallow users run debug mode. set false to disable.
    // enable if you want to add a "password"
    const QUERY_HASH_VAR = false;

    // hash GET variable to allow change production / debug mode on query string
    const QUERY_HASH_VAL = '112233';

    // default response type if not specified
    const DEFAULT_RESPONSE_FORMAT = 'json';

    // default response code if not set in controller
    const DEFAULT_RESPONSE_CODE = 200;

    // controllers directory
    const CONTROLLERS_DIR = 'Controllers';

    // try to redirect to a clean url when is malformed
    const ENABLE_REDIR = true;

    // enable or disable auth
    const ENABLE_AUTH = true;

    // show response errors in prodution mode
    const SHOW_RESPONSE_ERRORS = true;

    // use template for display errors
    const USE_TEMPLATE_PAGE = true;

    // default allowed domain for AJAX calls
    const DEFAULT_CROSSDOMAIN = '*';

    // allow ajax calls
    const ALLOW_AJAX_CALLS = true;

    // save error logs
    const ENABLE_ERROR_LOGS = true;

    // use detailed error logs

    // save access logs
    const ENABLE_ACCESS_LOGS = true;

    // use detailed access logs

    // logs default directory
    const DEFAULT_LOGS_DIR = 'logs';

    // handle logs in separated files
    const ENABLE_TRIM_LOGS = true;

    // max filze size of log in bytes [default 10240000 / 10 mb]
    const DEFAULT_MAX_LOG_SIZE = 10240000;

    // number of logs to rotate
    const DEFAULT_MAX_LOGS = 20;

    // enable cache
    const ENABLE_CACHE = false;

    // default cache ttl in seconds
    const DEFAULT_CACHE_TTL = 300;

    // cache default directory
    const DEFAULT_CACHE_DIR = 'cache';

    // maintence mode delete old cache files and log files
    const ENABLE_MAINTENCE = true;

    // seconds to run maintence: flush cache and log files [ default 7 days 604800 ]
    const DEFAULT_MAINTENCE_TTL = 604800;

    // seconds to consider old a cache file [ default one 12 days: 1036800 ]
    const DEFAULT_OLD_CACHE_TTL = 1036800;

    // seconds to consider old a log file [ default one 12 days: 1036800 ]
    const DEFAULT_OLD_LOGS_TTL = 1036800;

    // default http scheme when REST server is run over reverse proxy like nginx
    const DEFAULT_HTTP_SCHEME = 'http';

    // enable external debug console. please don't use this at production, will decrease performance.
    const ENABLE_CONSOLE = ENABLE_CONSOLE; // set from config to match remote console, you can set true or false here.

Building a controller is easy:

First of all you need to know if with method to use. (GET, POST, PUT, DELETE)

so you need a endpoint in

creat the Hello-World.php and put into Controllers dir

class Controller_Hello_World__index extends myRestController
    public function get()
         // set production or debug mode only in this controller / method
         $this->production = true;
         // print response
         $this->printResponse = true;
         // you can force response type to allowed ones, or specify the raw.
         // $this->responseType = 'raw';
         // grab params from query string
         $data = $this->request['params']['string']; // see wildcard controller
         // grab text
         $text = !empty( $data['name'] ) ? $data['name'] : 'Hello World!';
         // print response
         $this->response = $text;


now go to, you see the response, also you can add the parameter 

by default response is json, but you can change response type just adding .xml to query url

You need to create a public function for each request type/controller. with a specific name.

How to find the default name for your custom endpoint is easy, just enable debug mode and look at the response:

first of all point to the endpoint you want to create: and take a look to the controller array:

the file you need to create in controllers dir to make it work 
class: the name of class you need to use in controllers dir
wildcard: if you want to create endpoints like:


myRestServer have some in controller settings, wich applies only for current controller,
you need to create a settings function inside your controller file to enable functions:

class Controller_Hello_World__index extends myRestController
    // settings
    public function settings()
         $this->production = true; // set current controller in production or debug mode
         $this->auth['enabled'] = false; // enable / disable auth
         $this->auth['credentials'] = array( 'admin' => '123' ); // credentials access
         $this->auth['realm'] = 'Email read API endpoint'; // real
         $this->auth['methods'] = 'get'; // wich method want to protect or array of them
         $this->auth['digest'] = true; // use digest of basic auth
         $this->cache['enabled'] = false; // enable cache
         $this->cache['ttl'] = '300'; // ttl in secs for cache
         $this->logs['enabled'] = false; // enable / diable logs
         $this->logs['detailed'] = false; // enable detailed logs
    public function get()

Note: If you use settings function, will be called before your main method run (get,post,put,delete).

In addition myRestServer have more triggers to call in the method itself:

Setting Response headers:

$this->responseHeaders = 'MY-CUSTOM-HEADER: hello world from headers';

or in array mode

$this->responseHeaders[] = 'MY-CUSTOM-HEADER: hello world from headers';
$this->responseHeaders[] = 'API-POWERED-BY: myRest Server 1.0';


Setting response status:

You can set the response status of your application easy by calling:

$this->responseStatus = 404;

or with a simple logic:

if ($userAuth==true){
     $this->responseStatus = 200;
} else{
     $this->responseStatus = 401; // wich set the response code and status automatically to your browser

You can see all codes (and add more) in line 148 of myRestServer.php

Note: we don't recomend edit this unless you know exactly what you're doing.

Setting raw responses, in some cases we need raw responses instead of xml or json:
If you need to force response type for your controller just call:

$this->responseType = 'raw';
Note: you can force the response type to json, xml, php or raw, this overwrite the query string method (.json,.xml,php etc).
Special Note: raw mode can only be activated in the controller method, not in the query string


Print responses:

You can print everything you want to response if you send the proper string or array:

$this->response = 'Hello World';


$this-response = array('Hello','World');
Note: if you don't need to print anything just call the method: $this->printResponse = false;


MyRestServer is bundled with liveConsole an full AJAX powered console to help you to code and debug your application.

Note: We recommend to disable console when your app is in production mode.

You can track every controller so this will help you to develop your app in a nap of time.

to enable it open config.php from myRestSever base dir and change the desired values.

Note: default credentials for console: admin/gizmo

You can change on config.php from console dir

You can find full working examples on the Controllers dir such


You can find all demos in controllers dir, ready to use out of the box.


Once again, thank you so much for purchasing this script. As I said at the beginning, I'd be glad to help you if you have any questions relating to this script. No guarantees, but I'll do my best to assist. If you have a more general question relating to the script on CodeCanyon, you might consider visiting the forums and asking your question in the "Item Discussion" section.

Alterna Networks

Get Support or send us an email


jQuery Foundation
Twitter Bootstrap