Hi guys,

I don't even know where to start, the ideea is that I want to develope an API that responds with certain data, but I don't have a clue for what to look.

The ideea is that there is a panel like google analytics but with no stats, but some info for some users and I want to let them embed this into their pages as a service.
I think that Javascript or iframe, but I really dislike iframes.

Could you please point me for this method so that I know what to look for ? :)
Thanks.

Recommended Answers

All 3 Replies

Member Avatar for diafol

The data you serve will be based on the url (mod rewrite) with possible authentication (e.g. oauth2).

Once you get authentication out of the way deconstruct the url to see what info the user wants.

I sugegst returning data as json. As you know you can do this via json_encode().

quick e.g.

www.example.com/user/2367/

This tells you that the user wants to get data held for user 2367.

So you could have prepared mysqli queries, e.g. for user data and use '2367' in your execution

The returned data should be in array form that you can then format as json. Yopu just echo this.

The client (caller) can use a jQuery jsonp call for example to get this, if they want to use JS. Or use file_get_contents or even cURL (if fgc not possible for them), if they want to use PHP. The call to you is just the url (authentication aside), so it shouldn't matter if they request via RoR, java, asp.net, whatever.

I've really skimmed this topic and possibly made a few assumptions, but Dani is the experts here. She set up the DW API: have a look here for ideas:

My hobby site: http://dw.diafol.org/en/dw-badge/

Where the php call to DW is basically this format (PHP):

$json_array = json_decode(file_get_contents('http://www.daniweb.com/api/members/' . $id . '/'), true); 

Also here: http://dw.diafol.org/en/dw-box/

WHere I use jQuery and oAuth to extract info (based on code provided in Dani's API pages and Pritaeas' explanations (see threads with #daniweb-api tag)

http://www.daniweb.com/api/home

http://toys.lerdorf.com/archives/55-Writing-an-OAuth-Provider-Service.html

Diafol, thank you for your input, this is exactly what i want to do. It will be a small service for photographers like me to verify their dates for clients.
Let me chew your post so i can start working on it! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.