Home » Php » How to make Rest Api using codeigniter when getting output in html format

How to make Rest Api using codeigniter when getting output in html format

Posted by: admin June 30, 2018 Leave a comment

Questions:

Hi I have written code to retrieve books title from database table using codeigniter using this url

(localhost:81/sample_api/index.php/Book/get_books) when I type in browser i am getting output like this.
output:

So I want to make REST API for this actually i have tried so many github projects but they did in complicated way and I am unable to understand so please guid me how to make REST API in codeigniter for this link .

public function get_books() {
        $query = $this->db->get('tbl_books')->result();
        foreach ($query as $row) {
            echo $row->title."<br>";
        }
    }
Answers: