» CakePHP REST Plugin presentation

On twitter

At our company we have a lot of uses for a solid API. We can use it to distribute config files, have servers report in, let customers edit DNS records using their own interface, etc.
Now that I'm converting all of our legacy code to a big CakePHP application, the API needed a revisit as well. I chose to use REST as a standard, read about everything related to Cake & REST, and started hacking on a reusable plugin. The idea is that you can drop it in any application and unlock existing functionality to REST with minimal changes to your code.

It is still a work in progress, but as the first Dutch CakePHP event was held yesterday and I was asked to present something I thought this particular plugin might be of interest to the community. Here are the slides:

I would love some feedback to help it make better. My todos can be found in the slides as well, to give you an idea where I'm heading with this.

More info on the Dutch CakePHP event

 

Stay up to date

You can track my blog rss articles and rss comments. You may also find my rss bookmarks interesting. Or twitter Follow me on Twitter


Like this Article?

Your money is no good here, but
you can boost morale by spreading the word! : )


tags: cakephp, programming, rest, php, api
category: Programming - PHP - CakePHP
read: 4,253 times

Add comment

(required, shown)(required, not shown)for syntax highlighting

[CODE="Javascript"]
your_code_here();
[/CODE]

Replace "Javascript"
with "php", "text", etc.
code (to make sure you are not a spammer)

 Track replies: rss feed comments feed

Comments

#12. Paul Winkeler on 16 August 2010

Gravatar.com: Paul WinkelerThis REST plugin for cakephp is exactly what the Dr ordered. Does it indeed work for cakephp version 1.3 as well?

#11. Kevin on 29 June 2010

Twitter.com: kvz@ steve: Look like it's your webserver: http://www.checkupdown.com/status/E413.html

Furthermore, you may find the clien-side of this API interesting that I developed for my company:
http://github.com/true/true-api

#10. steve on 22 June 2010

Gravatar.com: steveHi... I figured out how to implement 2-legged OAuth with my API, but I now have another issue that I can't figure out. Have you ever executed a HTTP PUT with files? I keep getting 413 errors when send when I try to PUT anything to my API. Here are what the headers look like, any advice?:

[0] => Content-Disposition: attachment; filename="DSC01264.JPG"
[1] => Content-Type: application/octet-stream
[2] => Content-Length: 64250
... [more] [3] => Authorization: OAuth realm="", oauth_requester_id="720", oauth_signature_method="HMAC-SHA1", oauth_signature="Rom3hREK8p2PzMBXdzIJb3hy%2FF0%3D", oauth_nonce="4c210a01d83d9", oauth_timestamp="1277233665", oauth_token="", oauth_consumer_key="1385adb7be6ade0a0bf7d5493fd0722404c1795eb", oauth_version="1.0", xoauth_body_signature="8ap46NO3buRxIbzAtFc5OFa6FNY%3D"

thanks,

Steve

#9. steve on 11 June 2010

Gravatar.com: steveKevin thanks for the reply! Do you have any hints on how I could handle this Amazon Authentication... Do you happen to have an expample I could see?
I am building a REST API now, and I could use all the advice I could get.
Thanks!
Steve

#8. Kevin on 10 June 2010

Twitter.com: kvz@ steve: Hey, no your app still handles the authentication, that's what makes it flexible. But it parses the string for you and inside your login procedure you just check for it with

$this->Rest->credentials();


as (kind of) explained on: http://github.com/kvz/cakephp-rest-plugin

#7. steve on 08 June 2010

Gravatar.com: steveKevin,
Thank you very much for this plugin! I am a bit confused about the authentication. Does this plugin actually handle the Amazon-style authentication and return the appropriate HTTP response codes? Or, does it simply parse out the Amazon-style Header:

`Authorization: TRUEREST username=john&password=xxx&apikey=247b5a2f72df375279573f2746686daa`

... [more] into an array that can then be used effectively with some other security component?

Thanks,

Steve

#6. Kevin on 29 April 2010

Twitter.com: kvz@ gkibria: Did you make the necessary parseExtensions adjustments in your router so that Cake will try to parse json?

Your index is fine.
If in that controller you specify:

public $components = array(
'Rest.Rest' => array(
'debug' => 1,
'index' => array(
'extract' => array('products' => 'myProducts'),
),
),
);


It should show you the contents of products under 'myProducts' in json format, when you browse to /index.json

#5. gkibria on 24 April 2010

Gravatar.com: gkibriaThanks for info. But when I enable Rest.Rest component in products controller, I can't browse neither /products/index nor /products/index.json and after disable the component it works fine. any idea?

And Here is my index()

function index() {
$this->Product->recursive = 0;
$this->set('products', $this->paginate());

}


my cake_core is 1.25 thanks

#4. Kevin on 24 April 2010

Twitter.com: kvz@ gkibria: Only .json is supported for now. You should try that.
No the trick is you

$this->set('name', 'gkibria');

like you would normally with your index()

Only the restcomponent can take the viewVars you specify, maybe even convert them into another (more rest-consistent) format, and them json_encode them.
XML serialization is being worked on.

#3. gkibria on 24 April 2010

Gravatar.com: gkibriaHello

Thanks for your plugin. I have a products controller with index action working fine. When I added Rest.Rest component in my products controller I got "Error: The requested address '/products' was not found on this server." for /products

And /products.xml give me" XML Parsing Error: no element found"
... [more]
When I disable Rest.Rest component, /products are working fine. Can you tell me what's wrong?

Another thing, Do I have to place any additional code in index() action?

Many Thanks

#2. Kevin on 14 March 2010

Twitter.com: kvz@ Tamas Jozsa: Hey. No you tie it in with existing controllers & actions. So if you already have:
/posts/view/1

you could add the Rest component to your PostsController and then you could do
/posts/view/1.json
... [more]
to get the same data but in json format and with additional features like authentication

#1. Tamas Jozsa on 12 March 2010

Gravatar.com: Tamas JozsaHi Kevin,

This plug-in is exactly what I'm searching for. Will try it out today and when I have time I will return to give a feedback.

One thing I do not understand so far is, how to call this from a browser. Is it like:
... [more]
www.hostname.com/rest/<modelname>s ???

And how to select whether to output to JSON or XML. As I see in the code XML is there in many places.

Thanks,
Regards,
Tamas