2017 © Pedro Peláez
 

library codeigniter-restserver

REST Server for the CodeIgniter framework

image

chriskacerguis/codeigniter-restserver

REST Server for the CodeIgniter framework

  • Saturday, June 2, 2018
  • by chriskacerguis
  • Repository
  • 426 Watchers
  • 3994 Stars
  • 41,462 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2194 Forks
  • 14 Open issues
  • 20 Versions
  • 17 % Grown

The README.md

CodeIgniter RestServer

StyleCI, (*1)

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

Requirements

  • PHP 7.2 or greater
  • CodeIgniter 3.1.11+

Installation

composer require chriskacerguis/codeigniter-restserver

Usage

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:, (*3)

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

or run, (*4)

composer require chriskacerguis/codeigniter-restserver

Note that you will need to copy rest.php to your config directory (e.g. application/config), (*5)

Step 1: Add this to your controller (should be before any of your code), (*6)

use chriskacerguis\RestServer\RestController;

Step 2: Extend your controller, (*7)

class Example extends RestController

Basic GET example

Here is a basic example. This controller, which should be saved as Api.php, can be called in two ways:, (*8)

  • http://domain/api/users/ will return the list of all users
  • http://domain/api/users/id/1 will only return information about the user with id = 1
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

use chriskacerguis\RestServer\RestController;

class Api extends RestController {

    function __construct()
    {
        // Construct the parent class
        parent::__construct();
    }

    public function users_get()
    {
        // Users from a data store e.g. database
        $users = [
            ['id' => 0, 'name' => 'John', 'email' => 'john@example.com'],
            ['id' => 1, 'name' => 'Jim', 'email' => 'jim@example.com'],
        ];

        $id = $this->get( 'id' );

        if ( $id === null )
        {
            // Check if the users data store contains users
            if ( $users )
            {
                // Set the response and exit
                $this->response( $users, 200 );
            }
            else
            {
                // Set the response and exit
                $this->response( [
                    'status' => false,
                    'message' => 'No users were found'
                ], 404 );
            }
        }
        else
        {
            if ( array_key_exists( $id, $users ) )
            {
                $this->response( $users[$id], 200 );
            }
            else
            {
                $this->response( [
                    'status' => false,
                    'message' => 'No such user found'
                ], 404 );
            }
        }
    }
}

The Versions

02/06 2018

dev-master

9999999-dev https://github.com/chriskacerguis/codeigniter-restserver

REST Server for the CodeIgniter framework

  Sources   Download

MIT

The Requires

 

by Chris Kacerguis

31/03 2018

2.7.0

2.7.0.0

  Sources   Download

31/03 2018

2.7.1

2.7.1.0

  Sources   Download

31/03 2018

2.7.2

2.7.2.0

  Sources   Download

31/03 2018

v2.2

2.2.0.0

  Sources   Download

31/03 2018

v2.3

2.3.0.0

  Sources   Download

31/03 2018

v2.4

2.4.0.0

  Sources   Download

31/03 2018

v2.5

2.5.0.0

  Sources   Download

31/03 2018

2.6.0

2.6.0.0

  Sources   Download

31/03 2018

2.6.1

2.6.1.0

  Sources   Download

31/03 2018

v2.0

2.0.0.0

  Sources   Download

31/03 2018

v2.1

2.1.0.0

  Sources   Download

23/09 2017

3.0.3

3.0.3.0 https://github.com/chriskacerguis/codeigniter-restserver

REST Server for the CodeIgniter framework

  Sources   Download

MIT

The Requires

 

by Chris Kacerguis

23/09 2017

3.0.2

3.0.2.0 https://github.com/chriskacerguis/codeigniter-restserver

REST Server for the CodeIgniter framework

  Sources   Download

MIT

The Requires

 

by Chris Kacerguis

23/09 2017

3.0.1

3.0.1.0 https://github.com/chriskacerguis/codeigniter-restserver

REST Server for the CodeIgniter framework

  Sources   Download

MIT

The Requires

 

by Chris Kacerguis

09/08 2017

dev-development

dev-development https://github.com/chriskacerguis/codeigniter-restserver

REST Server for the CodeIgniter framework

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Chris Kacerguis

01/01 2017

3.0.0

3.0.0.0 https://github.com/chriskacerguis/codeigniter-restserver

REST Server for the CodeIgniter framework

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Chris Kacerguis

31/12 2016

2.8.0

2.8.0.0 https://github.com/chriskacerguis/codeigniter-restserver

REST Server for the CodeIgniter framework

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Chris Kacerguis

27/12 2016

2.7.4

2.7.4.0 https://github.com/chriskacerguis/codeigniter-restserver

REST Server for the CodeIgniter framework

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Chris Kacerguis

08/09 2016

2.7.3

2.7.3.0 https://github.com/chriskacerguis/codeigniter-restserver

REST Server for the CodeIgniter framework

  Sources   Download

MIT

by Chris Kacerguis