I'm trying to pull some data into my CakePHP site using a REST API. I'm familiar with CakePHP, but not with REST, so I'd like some guidance as to the best way to do this. I've looked online, but a lot of what I find is either telling me how to make my own A开发者_StackOverflow中文版PI, or it's quite old, and I'm not sure if it's still relevant.
The API documentation tells me to make the query request
http://api.sitename.com/rest/organizations/my_id/media.xml
where my_id
is a string that I have.
I'm using:
$url = http://api.sitename.com/rest/organizations/my_id/media.xml;
$result = file_get_contents($url);
and then I have the XML in $result.
Is this the best way to do this?
Short, direct answer to:
Is this the best way to do this?
No
Head over to the PHP cURL documenation for more info on how to "talk" to public web services.
After looking into cURL as Charles Sprayberry suggests, you'll then want to learn about parsing XML in PHP to be able to do something with the data that you retrieve.
I found this article to be useful for understanding a bit about Cake and ReST:
http://nuts-and-bolts-of-cakephp.com/2010/06/27/putting-semi-restful-api-development-to-rest/
精彩评论