首页 > 解决方案 > CodeIgniter Rest Api

问题描述

I'm implementing the api in codeigniter using the restcontroller and format files shown in the gist below, once inserted I implement the Api.php file in the path specified below but when I try to call the api as a test I get the following error 404 not found, what is it and how can I fix this?

url to call api get: http://localhost/api/Api/testget

I have this file (rest controller and format) https://gist.github.com/riccardopirani/8878fcda16cae2ad45e4b1c9e624f619

Php Code(in folder /controllers/api/Api.php:

<?php

use Restserver\Libraries\REST_Controller;

require(APPPATH.'libraries/REST_Controller.php');
   

      
    class Books extends REST_Controller {
      
        function testget()
        {
           $data = array("message"=>"RESTfull API sample");
           $this->response($data);
        }
            
    }

标签: phpcodeignitercodeigniter-3

解决方案


将方法名称写为test_get. 保持类和文件名相同,然后调用 (get) http://localhost/[projectname]/index.php/api/book/test


推荐阅读