Jump to content

An API


The Little Guy

Recommended Posts

I want to make an API for my site in the near future, I would like to know a few things...

 

Say I want the user to be able to do: $thing->search('some string'); on their server, and say I want to return an Array that may look like this:

Array
(
     [0] => Array
          (
               [id] => 12923551
               [title] => 'This is the title'
               [info] => 'This is some extra information'
          )
     [1] => Array
          (
               [id] => 32456581
               [title] => 'This is another title'
               [info] => 'This is some extra information'
          )
)

 

Then the user can use that array to do what they want on their server. Is this possible, if so how do you do this?

Link to comment
https://forums.phpfreaks.com/topic/186884-an-api/
Share on other sites

An api usually outputs the data as XML so you can have id, title etc as XML tags and the value of that inside the tag. You would need to use a mysql query to pull the data and then use DOM etc to insert the data into a tag and output it. Then the client site would use DOM to get the XML and parse it and output it to their visitors.

Link to comment
https://forums.phpfreaks.com/topic/186884-an-api/#findComment-986909
Share on other sites

So... After reading, what I understand, is that I would do something like this on my server:

 

$arr = array(1,2,3,4,5);
echo serialize($arr);

 

Then on the server that is using the API, they would have this:

 

// $opt contains the string that was returned using cURL
print_r(unserialize($opt));

 

Would this be correct?

Link to comment
https://forums.phpfreaks.com/topic/186884-an-api/#findComment-986923
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.