Where can I find examples of code that uses php and REST ?
Moderator: General Moderators
Where can I find examples of code that uses php and REST ?
I'm new to php and I have a couple of questions. I need to implement this and I don't know what direction to take.
I'm implementing a REST application that for example, the insert's method query string looks like this: "?format=xml&businessID=1234&customerId54321&itemID=123"
My question is,
Where/how do I get the values for businessId and customerId?
How do I invoke the script that will handle the logic for this service?
Can anyone point me in the right direction? Thanks.
I'm implementing a REST application that for example, the insert's method query string looks like this: "?format=xml&businessID=1234&customerId54321&itemID=123"
My question is,
Where/how do I get the values for businessId and customerId?
How do I invoke the script that will handle the logic for this service?
Can anyone point me in the right direction? Thanks.
Hi,
You would use REQUEST or GET
You would now have the value of businessId set in $business and the same for customerID
Hope this helps
Reece
You would use REQUEST or GET
Code: Select all
$business=$_REQUEST['businessId'];
$customer=$_REQUEST['customerId'];Hope this helps
Reece
What about in the web page
Thanks.
But what I'm most confused about is how you set that query string on the web page and send it. Any examples of the html code for that?
What event triggers my service to be called and how/where do I get the values for bussinesId and customerId inside the web page so I can put them in the query string before calling the service.
But what I'm most confused about is how you set that query string on the web page and send it. Any examples of the html code for that?
What event triggers my service to be called and how/where do I get the values for bussinesId and customerId inside the web page so I can put them in the query string before calling the service.
feyd | Please use
Now in the file this is linking to (page.php), you want to retrieve the GET variables posted to it, like this:
page.php:
Now you have all your variables in page.php from the address query.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
It's a simple HTML linkCode: Select all
<a href="page.php??format=xml&businessID=1234&customerId=54321&itemID=123">Link</a>page.php:
Code: Select all
<?
$format = $_GET['format'];
$businessID = (int) $_GET['businessID']; // use (int) to prevent attacks in mySQL, if this variable has anything other than a integer, it will become 0 (zero)
$customerID = (int) $_GET['customerID']; // I don't suggest using this in an address bar but it's your script
$itemID = (int) $_GET['itemID'];
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
If you're using a REST interface, creating a record should be done using the PUT method (or POST, since browsers are behind the ball supporting PUT and DELETE form methods). Rails differentiates with a hidden _method variable, so that may be a good standard way of working wround the browser limitation.
AJAX calls can be made via PUT and DELETE as well as GET and POST, so I would definitely support those first and foremost, using the alternative syntax as a workaround.
AJAX calls can be made via PUT and DELETE as well as GET and POST, so I would definitely support those first and foremost, using the alternative syntax as a workaround.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
REST is simply an interface for applying CRUD operations to data models, as far as I can tell. Some people are convinced that you're using REST to retrieve forms, etc... but I disagree. Using some of the principles behind REST when designing your routes is definitely good practice, but I wouldn't limit all your web calls to REST actions only. That's just bizarre IMO.
REST is all about the URI defining the resource and the METHOD defining the action. I dig that. Nested resources are where it gets coooool, because all of a sudden you have context! That's wicked.
REST is all about the URI defining the resource and the METHOD defining the action. I dig that. Nested resources are where it gets coooool, because all of a sudden you have context! That's wicked.