Codeigniter install rest api with composer

1.7k Views Asked by At

I install codeigniter with this: https://github.com/kenjis/codeigniter-composer-installer

When I try to install rest API: https://github.com/chriskacerguis/codeigniter-restserver

works fine when I extends REST_Controller, but how to run REST API Examples when I install him with Composer?

yep, this is dump questions

1

There are 1 best solutions below

0
Vishnu Bhadoriya On

Useful link : codeigniter-restserver Handling Request

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Api extends REST_Controller
{
  public function example_get()
  {
    echo "Called is called by Get method";
  }

  public function example_post()
  {
   echo "Called is called by Post method"; 
  }
}

?>

So you just need to call localhost/public/api/example this will call Api::example_get()

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 /example, for instance, it would call a Api#example_get() method else if you're making an HTTP POST call to /example, for instance, it would call a Api#example_post() method