Reputation: 129
Hi I want to create a Restful API in codeIgniter. So I started with testing chris kacer code (https://github.com/chriskacerguis/codeigniter-restserver), but when i tape
localhost:9090/CodeIgniter/index.php/example/user/id/1
I always get this response:
{"status":false,"error":"Unknown method."}
I don't know where is the problem. i configured my routes.php
($route['default_controller'] = "example";)
and config.php
($config['base_url'] = 'http://localhost:9090/CodeIgniter/';)
and it still not working. Can anyone help me please and thank you.
Upvotes: 1
Views: 1263
Reputation: 33
Looks like you haven't included the REST library class file. If that's the case then adding the lines below should resolve your error,
// including rest api class
require APPPATH . '/libraries/REST_Controller.php';
// use namespace
use Restserver\Libraries\REST_Controller;
Upvotes: 0
Reputation: 2366
When working with rest_codeighniter api the controller logic is kinda different in the sense that ur "methods/public functions" in the ur controller class(the one that extends the rest_controller) are created by combining the RESOURCE name and the HTTP method(e.g get,post,put etc). therefore if ur resource name is "user" and u want to make a "get" http call, ur method/function would be declared as "public function user_get(){ //ur code here } " .
Upvotes: 1