JustinK101 Posted March 25, 2009 Share Posted March 25, 2009 I need to create a REST API for an iPhone app. Let's say I have the following class: class Basic { //Constructor function __construct() { } public function set_id($p_id) { $sql = "INSERT INTO basic (`id`) VALUES (" . $p_id . ")"; mysql_query($sql) or die(mysql_error()); } public function get_id($p_id) { $sql = "SELECT `id` FROM basic WHERE `id` = " . $p_id; $result = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_object($result); return($row->id); } public function delete_id($p_id) { $sql = "DELETE FROM basic WHERE `id` = " . $p_id; mysql_query($sql) or die(mysql_error()); } } Assuming I have that simple class above, how do I make this a REST API? Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/150991-how-to-create-a-rest-api/ Share on other sites More sharing options...
ohdang888 Posted March 25, 2009 Share Posted March 25, 2009 this is a very general question Link to comment https://forums.phpfreaks.com/topic/150991-how-to-create-a-rest-api/#findComment-793281 Share on other sites More sharing options...
JustinK101 Posted March 25, 2009 Author Share Posted March 25, 2009 ohdang888, Sorry if I was too general. I guess I just don't know where to start. I am decent at object oriented php, but not sure the framework and methods I need to create a REST API. Thanks for the assistance, greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/150991-how-to-create-a-rest-api/#findComment-793356 Share on other sites More sharing options...
RichardRotterdam Posted March 25, 2009 Share Posted March 25, 2009 Looks like a DAO(Data Access Object) to me. What is it supose to do, what environment, what framework are you using. And what does REST has to do within this? Link to comment https://forums.phpfreaks.com/topic/150991-how-to-create-a-rest-api/#findComment-793408 Share on other sites More sharing options...
JustinK101 Posted March 25, 2009 Author Share Posted March 25, 2009 The above was just an example of what I want to do. Basically I need a REST interface, so a 3rd party iPhone developer can preform actions that need to be done. As I understand, REST works like: http://www.mydomain.com/api/get/98988 OR http://www.mydomain.com/api/insert/ Basically how do I go about creating the PHP code to handle the requests. Link to comment https://forums.phpfreaks.com/topic/150991-how-to-create-a-rest-api/#findComment-793413 Share on other sites More sharing options...
RichardRotterdam Posted March 25, 2009 Share Posted March 25, 2009 As I understand, REST works like: http://www.mydomain.com/api/get/98988 OR http://www.mydomain.com/api/insert/ Those look like urls that are rewritten. Without rewrite those urls wcould look like: www.mydomain.com/api/index.php?method=get&id=98988 It doesnt really have to do with anything under the hood. You don't even need to write OO code for this. Link to comment https://forums.phpfreaks.com/topic/150991-how-to-create-a-rest-api/#findComment-793453 Share on other sites More sharing options...
JustinK101 Posted March 25, 2009 Author Share Posted March 25, 2009 I guess I just don't know where to start. According to WikiPedia a REST API uses the URI to make requests, and you send the content type, GET, POST, PUT, DELETE to perform the actions. Link to comment https://forums.phpfreaks.com/topic/150991-how-to-create-a-rest-api/#findComment-793826 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.