Jump to content

Recommended Posts

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..  :-\

Link to comment
https://forums.phpfreaks.com/topic/211382-getting-started-with-api-how/
Share on other sites

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

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.

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

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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.