What is an API client library?
Client libraries are sometimes called helper libraries. What are they and how do they help developers use an API?
Over the past year I’ve run a few workshops on API Technical Writing. Part of the workshop content is about client libraries, and I decided it’s worth discussing this topic in a blog post too. It’s of interest to technical writers who are documenting APIs, particularly web services and REST APIs.
What is a client library?
A client library, sometimes called a helper library, is a set of code that application developers can add to their development projects. It provides chunks of code that do the basic things an application needs to do in order to interact with the API. For example, a client library may:
- Provide boiler-plate code needed to create an HTTP request and to process the HTTP response from the API.
- Include classes that correspond with the elements or data types that the API expects. For example, a Java client library can return native Java objects in the response from the API.
- Handle user authentication and authorisation.
How is that useful?
Looking at the developer who’s using the API: With a REST API or any web service API, the developer could be using any of a number of programming languages to make the API calls.
Wouldn’t it be great if we could give them some code in their own language, to help them get started with the API? That’s what a client library does. It helps to reduce the amount of code the application developers have to write, and ensures they’re using the API in the best supported manner.
Examples of client libraries
In some cases, the API developers provide client libraries for the API. In other cases, client libraries are developed and supported by the community rather than the API developer.
For example, here are the Flickr API client libraries listed by programming language, all maintained by the developer community:
Here are more examples of client libraries, listed per API:
Is a client library the same thing as an API?
No, although they’re closely related. My post on API types describes library-based APIs, which are libraries of code that developers need to import before they can use the API. So, how does that differ from a client library?
Here’s how I see the difference between library-based APIs and client libraries:
- Client libraries are additional libraries of code that are provided to make a developer’s life easier and to ensure applications follow best practices when using the API. In general, you can call the API directly without using the client library. (In some cases, though, the client libraries may be the preferred or even the only supported means of interacting with a particular service.)
I’d love to hear your thoughts on this topic – does the above summary make sense, is it useful, and what have I left out?