Jump to content

Where to start creating an API??


dazzathedrummer

Recommended Posts

Hi,

 

I'm developing an iPhone app that's going to need data from a MySQL database, it's just a simple list of my bands upcoming gigs.

 

So I understand that I need to build an API - I've found some scripts here and there, I just need some advice as to 'what' I should build...JSON? XML? something else?

 

I don't know anything about it and cant really find anything that will tell me.

 

Hopefully, If I can get a good method going I will be able to use it for various other app ideas.

 

 

Any suggestions are greatly appreciated.

Link to comment
Share on other sites

You could make this as simple as:

 

http://service.domain.top/bands.php

 

Returning whatever you fancy. Of course this will be very specific to your needs, so if you are planning on letting other people use this API you will probably have to add some formats like XML and JSON, or maybe even the good old CSV

 

http://service.domain.top/bands.xml

 

Would also be valid, updating it overnight with a CRON.

Link to comment
Share on other sites

Yeah pretty much.

 

You can pass your api key as a url parameter:

 

http://service.domain.top/bands.php?apikey=xxxxxx

 

In the question of xml vs json, from an efficiency standpoint you are better off using json as it is a much more terse format, and in mobile applications, it's highly advisable to send the data in the most compact form possible.

 

Php has a number of functions or you can use the zend_json library.  The best bet depends on the complexity of your json data, as well as how current a version of php you are using.

 

When you return your results, you want to set the correct header.

 

header('Content-type: application/json');

 

 

Link to comment
Share on other sites

wow thats really helped me - great information!!

 

So, i've created an api that outputs the gig date and venue.

 

Does this look like a format that can be read by the app (I don't know what format i'm aiming for).....

 

[{"2011-03-31 23:59:00":"O'Neill's , Peterborough"},{"2011-04-29 23:59:00":"O'Neill's, Peterborough"},{"2011-04-30 23:59:00":"The Cock Inn , Peterborough"},{"2011-05-06 23:59:00":"O'neills, Southend"},{"2011-05-19 23:59:00":"O'Neill's, Peterborough"},{"2011-05-21 23:59:00":"The Old Bridge Hotel, Huntingdon"},{"2011-05-29 23:59:00":"The Bell, Sawtry"},{"2011-06-09 23:59:00":"O'Neill's, Peterborough"},{"2011-06-18 23:59:00":"O'Neill's, Peterborough"},{"2011-07-07 23:59:00":"O'Neill's, Peterborough"},{"2011-07-09 23:59:00":"O'neills, Southend"},{"2011-07-15 23:59:00":"The Golden Fleece, Stamford"},{"2011-07-29 23:59:00":"O'Neill's, Peterborough"},{"2011-08-11 23:59:00":"O'Neill's, Peterborough"},{"2011-08-13 23:59:00":"Ebenezers, Peterborough"},{"2011-08-27 23:59:00":"O'Neill's, Peterborough"},{"2011-08-30 23:59:00":"The Old Coach House, Deeping"},{"2011-09-02 23:59:00":"Parkway Club, P'boro"},{"2011-09-15 23:59:00":"O'Neill's , Peterborough"},{"2011-09-17 23:59:00":"O'neills, Southend"},{"2011-09-30 23:59:00":"O'Neill's, Peterborough"},{"2011-10-06 23:59:00":"O'Neill's , Peterborough"},{"2011-10-15 23:59:00":"The Old Coach House, Deeping"},{"2011-10-28 23:59:00":"O'Neill's, Peterborough"},{"2011-11-10 23:59:00":"O'Neill's, Peterborough"},{"2011-11-12 23:59:00":"O'neills, Southend"},{"2011-11-26 23:59:00":"O'Neill's, Peterborough"},{"2011-12-08 23:59:00":"O'Neill's Duo, Peterborough"},{"2011-12-17 23:59:00":"The Golden Fleece, Stamford"},{"2011-12-23 23:59:00":"O'Neill's, Peterborough"},{"2011-12-24 23:59:00":"O'Neill's, Southend"}]

Link to comment
Share on other sites

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.