Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here


A fully RESTful server implementation for CodeIgniter using one library, one config file and one controller.

Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star blank 374f33e4d622a2930833db3cbea26b5d03dc44961a6ecab0b9e13276d97d6682Star blank 374f33e4d622a2930833db3cbea26b5d03dc44961a6ecab0b9e13276d97d6682 (1 ratings)
Rated 3.0 out of 5
Subscribe to updates I use codeigniter-restserver

Statistics on codeigniter-restserver

Number of watchers on Github 3850
Number of open issues 9
Average time to close an issue 16 days
Main language PHP
Average time to merge a PR 10 days
Open pull requests 33+
Closed pull requests 26+
Last commit almost 2 years ago
Repo Created over 10 years ago
Repo Last Updated almost 2 years ago
Size 3.74 MB
Organization / Authorchriskacerguis
Latest Release3.0.3
Page Updated
Do you use codeigniter-restserver? Leave a review!
View open issues (9)
View codeigniter-restserver activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating codeigniter-restserver for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

CodeIgniter Rest Server

Gitter chat

A fully RESTful server implementation for CodeIgniter using one library, one config file and one controller.


  1. PHP 5.4 or greater
  2. CodeIgniter 3.0+

Note: for 1.7.x support download v2.2 from Downloads tab

Important Update on 4.0.0

Please note that version 4.0.0 is in the works, and is considered a breaking change (per SemVer). As CI 3.1.0 now has native support for Composer, this library will be moving to be composer based.

Take a look at the development branch to see what's up.

Installation & loading

CodeIgniter Rest Server is available on Packagist (using semantic versioning), and installation via composer is the recommended way to install Codeigniter Rest Server. Just add this line to your composer.json file:

"chriskacerguis/codeigniter-restserver": "^3.0"

or run

composer require chriskacerguis/codeigniter-restserver

Handling Requests

When your controller extends from REST_Controller, the method names will be appended with the HTTP method used to access the request. If you're making an HTTP GET call to /books, for instance, it would call a Books#index_get() method.

This allows you to implement a RESTful interface easily:

class Books extends REST_Controller
  public function index_get()
    // Display all books

  public function index_post()
    // Create a new book

REST_Controller also supports PUT and DELETE methods, allowing you to support a truly RESTful interface.

Accessing parameters is also easy. Simply use the name of the HTTP verb as a method:

$this->get('blah'); // GET param
$this->post('blah'); // POST param
$this->put('blah'); // PUT param

The HTTP spec for DELETE requests precludes the use of parameters. For delete requests, you can add items to the URL

public function index_delete($id)
        'returned from delete:' => $id,

If query parameters are passed via the URL, regardless of whether it's a GET request, can be obtained by the query method:

$this->query('blah'); // Query param

Content Types

REST_Controller supports a bunch of different request/response formats, including XML, JSON and serialised PHP. By default, the class will check the URL and look for a format either as an extension or as a separate segment.

This means your URLs can look like this:

This can be flaky with URI segments, so the recommend approach is using the HTTP Accept header:

$ curl -H "Accept: application/json"

Any responses you make from the class (see responses for more on this) will be serialised in the designated format.


The class provides a response() method that allows you to return data in the user's requested response format.

Returning any object / array / string / whatever is easy:

public function index_get()

This will automatically return an HTTP 200 OK response. You can specify the status code in the second parameter:

public function index_post()
    // ...create new book
    $this->response($book, 201); // Send an HTTP 201 Created

If you don't specify a response code, and the data you respond with == FALSE (an empty array or string, for instance), the response code will automatically be set to 404 Not Found:

$this->response([]); // HTTP 404 Not Found


You can overwrite all default configurations by creating a rest.php file in your config folder with your configs. All given configurations will overwrite the default ones.


You can overwrite all default language files. Just add a rest_controller_lang.php to your language and overwrite the what you want.

Multilingual Support

If your application uses language files to support multiple locales, REST_Controller will automatically parse the HTTP Accept-Language header and provide the language(s) in your actions. This information can be found in the $this->response->lang object:

public function __construct()

  if (is_array($this->response->lang))
    $this->load->language('application', $this->response->lang[0]);
    $this->load->language('application', $this->response->lang);


This class also provides rudimentary support for HTTP basic authentication and/or the securer HTTP digest access authentication.

You can enable basic authentication by setting the $config['rest_auth'] to 'basic'. The $config['rest_valid_logins'] directive can then be used to set the usernames and passwords able to log in to your system. The class will automatically send all the correct headers to trigger the authentication dialogue:

$config['rest_valid_logins'] = ['username' => 'password', 'other_person' => 'secure123'];

Enabling digest auth is similarly easy. Configure your desired logins in the config file like above, and set $config['rest_auth'] to 'digest'. The class will automatically send out the headers to enable digest auth.

If you're tying this library into an AJAX endpoint where clients authenticate using PHP sessions then you may not like either of the digest nor basic authentication methods. In that case, you can tell the REST Library what PHP session variable to check for. If the variable exists, then the user is authorized. It will be up to your application to set that variable. You can define the variable in $config['auth_source']. Then tell the library to use a php session variable by setting $config['rest_auth'] to session.

All three methods of authentication can be secured further by using an IP white-list. If you enable $config['rest_ip_whitelist_enabled'] in your config file, you can then set a list of allowed IPs.

Any client connecting to your API will be checked against the white-listed IP array. If they're on the list, they'll be allowed access. If not, sorry, no can do hombre. The whitelist is a comma-separated string:

$config['rest_ip_whitelist'] = '123.456.789.0, 987.654.32.1';

Your localhost IPs ( and are allowed by default.

API Keys

In addition to the authentication methods above, the REST_Controller class also supports the use of API keys. Enabling API keys is easy. Turn it on in your config/rest.php file:

$config['rest_enable_keys'] = TRUE;

You'll need to create a new database table to store and access the keys. REST_Controller will automatically assume you have a table that looks like this:

    `key` VARCHAR(40) NOT NULL,
    `level` INT(2) NOT NULL,
    `ignore_limits` TINYINT(1) NOT NULL DEFAULT '0',
    `date_created` INT(11) NOT NULL,
    PRIMARY KEY (`id`)

The class will look for an HTTP header with the API key on each request. An invalid or missing API key will result in an HTTP 403 Forbidden.

By default, the HTTP will be X-API-KEY. This can be configured in config/rest.php.

$ curl -X POST -H "X-API-KEY: some_key_here"


Codeigniter Profiler feature has been added to the library, so that you can use the power of CI profiler in your project just by setting config parameter to enable profile through out your application Turn it on in your config/config.php file:

TRUE to turn profile ON, FALSE to turn it off
$config['enable_profiling'] = FALSE;

Also you need to enable hooks in your config.php that looks like this

$config['enable_hooks'] = TRUE;

Also you can refer to config/config.php.sample

Other Documentation / Tutorials


This project was originally written by Phil Sturgeon, however his involvement has shifted as he is no longer using it. As of 2013/11/20 further development and support will be done by Chris Kacerguis.

Pull Requests are the best way to fix bugs or add features. I know loads of you use this, so please contribute if you have improvements to be made and I'll keep releasing versions over time.

codeigniter-restserver open issues Ask a question     (View All Issues)
  • over 3 years Problem with "simple" POST error uknown method
  • over 3 years Request: Would you consider implementing something like this?
  • over 3 years response() is called before _log_request() in _remap() when force_https and rest_enable_logging
  • over 3 years Caching
  • over 3 years How can I use multiple database?
  • over 3 years About Loading Timer
  • over 3 years A fix for index methods
  • over 3 years DELETE parameters
codeigniter-restserver open pull requests (View All Pulls)
  • Corrections on auth_override and Reading Authorization
  • Limit lookup optimization
  • Remove the exit() of REST_Controller->response()
  • Updated API before possible release
  • Add CORS access control checking
  • Added method to check if request body has expected keys
  • Add traditional chinese language support.
  • In case of json put request parsed body in order to get the parameters.
  • Adds german to the default languages
  • Response code changed
  • fix json_encode for integer values
  • Check if API KEY submitted is activated
  • Minor style guide fixes
  • Feature: tokens and clean Logs
  • Update path to config file in Rest_server.php
  • Support chinese utf8
  • response continue fix
  • fix cross site to option request error
  • Fixing SQL error when saving logging and using different locale settings
  • Code smell, PHP Doc problems, Index methods, and global exception handler
  • Add Indonesian language
  • Support Chinese better
  • bug fix request
  • All around cleaning
  • Adding JWT Authentication to CodeIgniter Rest Server
  • Using composer to autoload Format library.
  • Insert comma and then a space in allowed headers and methods.
  • Update rest_controller_lang.php
  • bugfix: fatal error if check_cors and rest_enable_logging are both enabled
  • update translate
  • Add config to force CORS pre-flight headers to be included
  • load rest config, correct missing vars - Migrations (#820)
  • dev
codeigniter-restserver questions on Stackoverflow (View All Questions)
  • Errors in codeigniter-restserver library
  • Codeigniter 3 and codeigniter-restserver not working
  • codeigniter-restserver: digest auth always returns "invalid credentials"
  • Codeigniter restserver getting ERR_CONNECTION_RESET when trying to load examples
  • codeigniter restserver set cache header
  • HTTP OPTIONS error in Phil Sturgeon's Codeigniter Restserver and Backbone.js
  • local vs hosted restful service. angular and codeigniter restserver
  • Codeigniter-restserver does not accept POST method CORS
  • enabling cors in codeigniter ( restserver by @chriskacerguis )
  • How to send DELETE request to phil sturgeon's - codeigniter-restserver
  • Codeigniter RESTserver. Null response
  • Authentication codeigniter-restserver
  • CodeIgniter Restserver doesn't work with specific URL's
  • How to send POST request to Phil Sturgeon's CodeIgniter RestServer
  • issues with backbone.js DELETE request and codeigniter restserver (phils)
codeigniter-restserver list of languages used
codeigniter-restserver latest release notes
3.0.3 3.0.3

Various big fixes

3.0.2 3.0.2

Fix: A Database Error Occurred when update logs. Thanks @ganl

3.0.1 3.0.1

lots of fixes and composer support. Lots and lots of thanks to @Hanisch-IT

Other projects in PHP