• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
REST implementation for CodeIgniter

[eluser]Phil Sturgeon[/eluser]
Finally got a fully working REST implementation with support for JSON, XML, CSV, HTML tables, PHP export and serialization.

It supports multiple POST, GET, PUT and DELETE methods within a single rest controller and provides the methods $this->get(), $this->put() and $this->post() for accessing parameters from within the controller that all run through the input library for XSS protection.

Check out my article REST implementation for CodeIgniter.

You can have one rest.php or api.php file for your ENTIRE site, or using modules/sub-directories you can have one for each section.


Let me know what you think. I'd love some feedback on this.

Excellent work Phil (as always) Wink
Although it will be a while before I need to use this, it looks simple enough Smile

[eluser]Yorick Peterse[/eluser]
You stole my API ! Tongue

[quote author="Yorick Peterse" date="1244061632"]You stole my API ! Tongue[/quote]

I think the term you're looking for is 'enhanced' Tongue
And just cause you started one first means no one else can happen to do one at the same time? Tongue

[eluser]Phil Sturgeon[/eluser]
I modified it at first but it has evolved past all recognition. I didn't simply add a few more functions into your work, I re-coded the whole logic too it.

The only code I copied in the end was:


but even that changed to:


I have to say your API was a great source of inspiration though, helped out a lot. :-)

[eluser]Yorick Peterse[/eluser]
Haha, I don't mind Tongue I have given myself a month to finish the API for Flork, so it will improve a lot

p.s. Phil, your logo is ready Smile

Great—just what I needed. I'll definitely check it out.

And in case it helps: I'm using a small extension for the Router to fetch the response format:
class MY_Router extends CI_Router
    public function _validate_request($segments)
        /* get response format */
        $last_segment = $segments[count($segments)-1];
        $last_segment_arr = split('\.', $last_segment);
        $segments[count($segments)-1] = $last_segment_arr[0];

        if ( isset ($last_segment_arr[1]))
            $this->response_format = $last_segment_arr[1];


Now I can use URLs like
and get the response format via
in my controller.

It's not pretty but it seems to work fine so far. I'm happy about better suggestions, though.


[eluser]Phil Sturgeon[/eluser]
That is a possibility but I felt dirty enough adding /format/xml onto it. People should be requesting formats properly using MIME types instead of worrying about pretty URL's.

I'm amazed with the traffic coming in for this article. In two days it has almost caught up with the article introducing PyroCMS which was published a month ago!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.