General Question

bluemukaki's avatar

How do I go about creating an API for a website?

Asked by bluemukaki (4332points) August 23rd, 2008

What is required, what do I need to know how to do etc.

Observing members: 0 Composing members: 0

5 Answers

paulc's avatar

You should start by defining what kind of data and methods you want to expose. Then you’ll want to decide how the API is accessed including authentication.

Most often, data is exposed with XML. There are some existing standards out there such as XML-RPC (which is a much more manageable than SOAP). Of course, there’s nothing wrong with rolling your own format if you want to keep things simple. Most of the time when exposing methods that don’t return data you’ll want to return some sort of response indicating the success or failure of the request. I’ve seen many APIs that always return a standard response with the data that may or may not be returned by it wrapped inside the response. The utility here is that you can always expect some kind of standard response for each request.

Determining how the API is accessed is something to put thought in to as well. Most APIs out there, though, receive requests via HTTP POST. Some places use a namespace style of naming their methods (eg. “news.create”, “friends.jellies.getAll”) but whatever you decide is ultimately not going to be a big problem for anyone accessing it (just be sure to document it!)

Finally, when it comes to authentication it is a matter of your desire for security. It is possible that you won’t need authentication but if you are creating a system where you have users or access tiers then you’ll need something. One of the more effective methods is an access token exchange where the client requests an access token from your API by supplying an ID and a secret of some sort (password). If these credentials are valid, your system then creates a token that is good for a certain period of time and you return it to the client. When the client makes requests to the API, the token is expected and you need only validate it and check for its expiration.

I’d suggest taking a look at some APIs out there right now to get a feel for their operation. Check out Flickr, any of Google’s APIs (these are well designed in my opinion) or maybe Twitter. Hope that helps.

roadventer's avatar

This question is nonsensical. It is analogous to asking, “How do I build a machine?” In the absence of providing at least some information about the nature of the machine you want to build, it is impossible to provide a meaningful answer to that question. Similarly, in the absence of providing meaningful information about the nature of your website and the functionality you want to expose in an API, you can’t get a meaningful answer. (I regret that paulc above has tried to answer your question, but his answer incorporates numerous unproven assumptions about you and your question.)

My guess is that you want to do this because one or more people said you should do this, but really, you don’t know what “this” is.

You would be well advised to find somebody who understands what you are talking about (i.e. a person who is at least semi-technically familiar with web development) so that he/she can restate your concern back to you in a manner that might help you meaningfully understand it.

bluemukaki's avatar

Well, actually, roadventer, no I don’t know exactly what ‘this’ is but thats probably why I’m asking other people. Maybe the fact that paulc’s answer helped me a lot, and that I’m not allowed to promote my site on here so I decided not to post a link to it or mention what it is limits my ability to question- this is merely a starting block, whereas you expect everyone to be halfway down the pool before they start.

You’ll notice that I used the words ’go about creating’ which doesn’t necessarily determine the exact form and function of an API, merely the steps I could to go towards to make it, people can ask others questions like “How do I get to town”, but you wouldn’t give them directions from halfway. If I had said ‘How do I create an API’ then your claims would be justified, but they’re not so shut your mouth.

This question makes perfect sense and you are a dipshit. If you’re so smart and know so much about API’s, why don’t you offer something worthwhile to the conversation- not some smart arse comment about how the question isn’t specific enough for you.

Oh look, 5 Great Answer points for paulc, maybe the question was worth answering after all. You’ll notice his first sentence addresses the question perfectly.

PS. I’m grumpy today, please excuse my ranting.

benseven's avatar

I think you have a point, roadventer’s answer also makes certain unproved assumptions about you yourself having a lack of technical knowledge, when anyone who’s used this site for a while would realise this is not the case.

I also don’t think that was a rant – just the perfect balance between informative, cutting and offensive ;)

joeysefika's avatar

touche, bluemukaki, touche

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther