Welcome Guest, Not a member yet? Register   Sign In
Is REST API Possible with Codeigniter?
#5

(12-09-2017, 06:06 AM)mahesh2150 Wrote: That is a good tutorial.
...
Is it maintained by codeigniter?

CodeIgniter does not include a REST API so no, the tutorial is not maintained by CodeIgniter.

(12-09-2017, 06:06 AM)mahesh2150 Wrote: Is it safe to use in my projects?
What do you mean by safe?

As far as it goes the code should work but I would say there are problems. The main one being that user input is being trusted without being verified or sanitized. Never trust user input! There might be other issues but I did not examine the tutorial in depth.

From my point of view there is some coding there that (at best) points to a less than full understanding of CodeIgniter or (at worst) indicates a thoughtless approach to coding. For instance, this bit of code.
PHP Code:
  //API call - add new book record
 
   public function add($data){

 
       if($this->db->insert('tbl_books'$data)){
 
          return true;
 
       }else{
 
          return false;
 
       }
 
   

The if statement is totally unnecessary. Since index() returns true or false why use the if conditional? Instead, simply return the results from index().

PHP Code:
  //API call - add new book record
 
   public function add($data){
 
       return $this->db->insert('tbl_books'$data));
 
   

And again the input is accepted "as-is" which is far from a best practice.

To be fair, it's important to recognize that the tutorial is not presented as complete and robust production level code. It simply demonstrates basic concepts.

(12-09-2017, 06:06 AM)mahesh2150 Wrote: But missing the security part.
How to give access to the specific user only? OAuth?

You are asking about Authentication which is a separate concern from REST API.

There are many third-party authentication libraries build for CodeIgniter. Community Auth and Ion_Auth are but two that are in wide use. There are others and also lots of examples on how to do-it-yourself. Any of these could be integrated using a RESTful API.
Reply


Messages In This Thread
RE: Is REST API Possible with Codeigniter? - by dave friend - 12-09-2017, 08:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB