V Posted August 21, 2010 Share Posted August 21, 2010 I'm trying to learn how to create a simple API, possibly using REST. I found a lot of online tutorials on how to implement API's but how do I create my own for my own website? The API I want to make is just for querying simple data and inserting data in the DB. From what I learned, REST does HTTP requests from a XML or JSON file but is REST a script I have to download, I can't find a REST site. I'm confused.. :-\ Quote Link to comment https://forums.phpfreaks.com/topic/211382-getting-started-with-api-how/ Share on other sites More sharing options...
MadTechie Posted August 21, 2010 Share Posted August 21, 2010 REST is a concept REpresentational State Transfer Quote Link to comment https://forums.phpfreaks.com/topic/211382-getting-started-with-api-how/#findComment-1102159 Share on other sites More sharing options...
V Posted August 21, 2010 Author Share Posted August 21, 2010 Oooh I see! Thanks! Do you know where I could find some REST examples? Verything API related seems to be Twitter or Facebook.. Quote Link to comment https://forums.phpfreaks.com/topic/211382-getting-started-with-api-how/#findComment-1102184 Share on other sites More sharing options...
dreamwest Posted August 22, 2010 Share Posted August 22, 2010 An rss feed is an API, its really that simple - you can make it any type of application http://site.com/example.php: (on your site) <?php $go = $_GET['q']; echo $go; ?> On the developers site echo file_get_contents('http://site.com/example.php?q=funny'); Which will output "funny" on the developers site Thats all an API is Quote Link to comment https://forums.phpfreaks.com/topic/211382-getting-started-with-api-how/#findComment-1102280 Share on other sites More sharing options...
V Posted August 22, 2010 Author Share Posted August 22, 2010 dreamwest thanks, that's the simplest API explanation I saw Is file_get_contents like CURL? Quote Link to comment https://forums.phpfreaks.com/topic/211382-getting-started-with-api-how/#findComment-1102348 Share on other sites More sharing options...
ignace Posted August 22, 2010 Share Posted August 22, 2010 REST uses HTTP which makes it very lightweight, a few examples of REST: -- create the user PUT /users Host: www.phpfreaks.com Accept: text/xml Accept-Encoding: UTF-8 username=ignace&password=password -- read the user info GET /users/ignace Host: www.phpfreaks.com Accept: text/xml Accept-Encoding: UTF-8 Authorization: user ignace:password -- update the profile info POST /users/ignace Host: www.phpfreaks.com Accept: text/xml Accept-Encoding: UTF-8 Authorization: user ignace:password avatar=RESTful.jpg&signature=Posted%20Using%20REST -- delete it DELETE /users/ignace Host: www.phpfreaks.com Accept: text/xml Accept-Encoding: UTF-8 Authorization: user ignace:password Full CRUD-functionality. Quote Link to comment https://forums.phpfreaks.com/topic/211382-getting-started-with-api-how/#findComment-1102456 Share on other sites More sharing options...
V Posted August 23, 2010 Author Share Posted August 23, 2010 Ignance thanks for the example! However I have no idea how to use that. I'll try and request a REST tutorial on the boards Quote Link to comment https://forums.phpfreaks.com/topic/211382-getting-started-with-api-how/#findComment-1102539 Share on other sites More sharing options...
MadTechie Posted August 23, 2010 Share Posted August 23, 2010 you can't get a REST tutorial for an API that doesn't exist! the fact is your attempting to write something that's going to be unique to your site, with the info above, I'm not sure what else your need, other then working out what you need to access via the API and what inputs and outputs your going to be using Quote Link to comment https://forums.phpfreaks.com/topic/211382-getting-started-with-api-how/#findComment-1102544 Share on other sites More sharing options...
V Posted August 23, 2010 Author Share Posted August 23, 2010 MadTechie yes that makes sense. I'm just trying to find a very basic API example using the REST method and from then I can figure out how to develop my own. There's no (easy to understand) documentation on it, yet everyone says it's simple.. Quote Link to comment https://forums.phpfreaks.com/topic/211382-getting-started-with-api-how/#findComment-1102545 Share on other sites More sharing options...
MadTechie Posted August 23, 2010 Share Posted August 23, 2010 Do you have a list of actions you wish to perform via an API ? Quote Link to comment https://forums.phpfreaks.com/topic/211382-getting-started-with-api-how/#findComment-1102560 Share on other sites More sharing options...
V Posted August 24, 2010 Author Share Posted August 24, 2010 Yes, just insert into the DB and query from the DB Quote Link to comment https://forums.phpfreaks.com/topic/211382-getting-started-with-api-how/#findComment-1103325 Share on other sites More sharing options...
MadTechie Posted August 25, 2010 Share Posted August 25, 2010 Yes, just insert into the DB and query from the DB Well Insert is a query !?! but anyways Create 2 a script that accepts 3 parameters (List, Add, Name) /index.php?List=Usernames Would be used to list all users /index.php?Add=Username&Name=MadTechie would be used to Add a User Quote Link to comment https://forums.phpfreaks.com/topic/211382-getting-started-with-api-how/#findComment-1103433 Share on other sites More sharing options...
V Posted August 25, 2010 Author Share Posted August 25, 2010 Thanks MadTechie I think the API concept is starting to make sense Quote Link to comment https://forums.phpfreaks.com/topic/211382-getting-started-with-api-how/#findComment-1103684 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.