Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Background

I have no idea how to use an API.

I know that all APIs are different, but I've been doing research and I don't fully understand the documentation that comes along with them. There's a programming competition at my university in a month and a half that I want to compete in (revolved around APIs) but nobody on my team has ever used one. We're computer science majors, so we have experience programming, but we've just never been exposed to an API. I tried looking at Twitter's documentation, but I'm lost.

Would anyone be able to give me some tips on how to get started? Maybe a very easy API with examples, or explaining essential things about common elements of different APIs? I don't need a full-blown tutorial on Stack Overflow; I just need to be pointed in the right direction.

Update

The programming languages that I'm most fluent in are C (simple text editor usually) and Java (Eclipse). In an attempt to be more specific with my question: I understand that APIs (and yes, external libraries are what I was referring to) are simply sets of functions.

Question

I guess what I'm trying to ask is how I would go about accessing those functions. Do I need to download specific files and include them in my programs, or do they need to be accessed remotely, etc.?

share
8  
I think you're fundamentally mis-understanding what an API is. You can't do programming of any kind without an API. –  skaffman Feb 12 '11 at 16:17
1  
Details, details, details. API is a veery general term, the only answer to 'How to use an API?' I can think of is 'You just use it'. What kind of API are you talking about? –  Cat Plus Plus Feb 12 '11 at 16:19
    
@skaffman: he's probably talking about external libraries. @GRardB: It's next to impossible to answer your question without knowing which programming language you use, which particular API would you like to use and even which development tools (IDE, build tool, etc.) you use. –  Goran Jovic Feb 12 '11 at 16:21
    
@GRardB: do you have access to some sample code that uses the API for various tasks? The early step of picking up a new API is a little like learning a few phrases of a foreign language - a gibberish which you try to mimic, along with the explanation of what that sentence means. –  rwong Feb 12 '11 at 21:40
comments disabled on deleted / locked posts

migration rejected from stackoverflow.com Apr 12 at 17:18

This question came from our site for professional and enthusiast programmers. Votes, comments, and answers are locked due to the question being closed here, but it may be eligible for editing and reopening on the site where it originated.

put on hold as too broad by gnat, Bart van Ingen Schenau, Robert Harvey, World Engineer Apr 12 at 17:18

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

It really depends on the API. A lot of popular ones lately are web-based, meaning to use them you basically send a formatted request to a server and parse the response using whatever means you like.

For a C library, you generally just add an #include to your file, and when you compile it, you add a -I option to point to the right include files, and a -l option to link with the library implementation.

For example, to use libxml2 on linux, you add #include <libxml/parser.h> to your file, and compile with:

gcc -I/usr/include/libxml2 -lxml2 myfile.c

If you told us which one you were specifically interested in, we can give you better guidance.

share
add comment

An Application Programming Interface (API) is a doorway into the programming model that a company exposes so you can enhance or extend some capability they provide. For example, Facebook wants to help programmers develop applications that work with their platform. So they offer a library that you include with your application to access data in the Facebook system.

In most cases the best platform to use these public APIs is Windows, simply because it has the largest developer audience.

So how to do you get started? You download an SDK (software development kit). SDKs include the libraries, documentation, samples, help files, and so on that the company uses to help you get started. I've only worked on about 18 SDKs, so I'm no expert, but let's take Facebook for an example. Go to developers.facebook.com. Search for "SDK". Download the version for your platform. Look at the samples. Try them. Change them to do something slightly different.

And yes, it's difficult. But let me give you a hint. It's also fun. In an intellectually stimulating way. Sort of like when you first develop a chess strategy.

share
add comment