APIs
APIs
What would be the best way to develope a basic read only API to get user information to be displayed and used (from the database) on another website?
I have been looking for some decent AJAX tutorials to produce one (as i think they will probably be the safest) but there is no way of turning the returned values into php variable arrays / objects. (if there is i havnt found it)
The only sane solution i can find is php cURL. But this would mean that anyone wanting to use the API would need to have a cURL enabled host.
Is there any other ways i can do this?
The goal is to make an API in which a class script can be included and initialized, or somekind of source link in which a user can add their access key etc to in order to access it.
It really needs to be able to return a php array or object. Unless someone can suggest a way of doing it through ajax.
ta muchly
nighty night xx
I have been looking for some decent AJAX tutorials to produce one (as i think they will probably be the safest) but there is no way of turning the returned values into php variable arrays / objects. (if there is i havnt found it)
The only sane solution i can find is php cURL. But this would mean that anyone wanting to use the API would need to have a cURL enabled host.
Is there any other ways i can do this?
The goal is to make an API in which a class script can be included and initialized, or somekind of source link in which a user can add their access key etc to in order to access it.
It really needs to be able to return a php array or object. Unless someone can suggest a way of doing it through ajax.
ta muchly
nighty night xx
New Site Coming Soon! Stay tuned 
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: APIs
So the key problem here is to get a value from AJAX into a PHP object? That would only require a simple variable assignment in the AJAX's called PHP script. However, I am thinking I am missing part of the issue here.
The indelible lord of tl;dr
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: APIs
My javascript tutorial uses a simple method to use ajax to retrieve PHP arrays and data. Just build from it. I hate JSON, makes no sense to me when it is soo simple to just use standard data and split it.
Re: APIs
Why bother splitting data from PHP and later on, in your JS doing heavy string operations? A JSON object is almost the same as a JS object, in fact, there are few differences. It`s a big array with objects inside of it. You can loop through them as simple as for(obj in jsonObj){ /*do something */ }
Ohhwell, i`m not to judge anyway, i picked up JS last month lol. My Js knowledge in raw js is limited.
Ohhwell, i`m not to judge anyway, i picked up JS last month lol. My Js knowledge in raw js is limited.
Re: APIs
thanks halls ill look at your tuts and see what i can find 
@Xaleph
I have never really used JS let alone JSON and never heard of JSONP lol. you got any links to simple tuts which show you how to use it effectivly?
thanks for the input guys
@Xaleph
I have never really used JS let alone JSON and never heard of JSONP lol. you got any links to simple tuts which show you how to use it effectivly?
thanks for the input guys
New Site Coming Soon! Stay tuned 
Re: APIs
What, that's like saying "I hate JavaScript" all JSON is is an array in JavaScript.hallsofvallhalla wrote:I hate JSON
An array:
Code: Select all
Array ( [foo] => bar )
Code: Select all
$array = array( 'foo' => 'bar' );
Code: Select all
var array = new Array( 'foo' => 'bar' );
Code: Select all
var array = { 'foo' : 'bar' }; // actually an object, array would be [ 'foo' : 'bar' ]
Code: Select all
a:1:{s:3:"foo";s:3:"bar";}
JSON
Code: Select all
{"foo":"bar"}
Fighting for peace is declaring war on war. If you want peace be peaceful.
Re: APIs
i have sorted a api feed out .
i use the api address that i was given and then the key . and sort it in a sql database and then just show what info i require .
If this is what you are on about i can post how i did it .
if you want this side or was you after the create the api side so others can use the info?
Dave
i use the api address that i was given and then the key . and sort it in a sql database and then just show what info i require .
If this is what you are on about i can post how i did it .
if you want this side or was you after the create the api side so others can use the info?
Dave