Is there a difference between a library and an API?

Whenever I ask people about the difference between an API and a library, I get different opinions. Some give this kind of definition, saying that an API is a specification, and a library is an implementation ...

Some will tell you this type of definition, that an API is a collection of displayed functions, and a library is simply distribution into a compiled form.

All this makes me wonder, in the world of web code, frameworks and open-source, is there really a practical difference? Can a library like jQuery or cURL overlap with an API definition?

Also, do frameworks really intersect in this category? Is there a part of Rails or Zend that could be more "API-like" or "libraryesque"?

Really looking forward to some enlightened thoughts :)

+42
api frameworks paradigms
Sep 09 '10 at 16:45
source share
7 answers

I believe that when I talk about the API, it means only those parts that are subject to the programmer. If I'm talking about the "library", then I also mean everything that works "under the hood", although part of the library is still.

+50
Sep 09 '10 at 16:48
source share

The API is part of a library that defines how it will interact with external code. Each library has an API, an API is the sum of all publicly available / exported materials. The value of the API is currently expanding. we could name the way the website and service interact with code as an API. You can also say that a device has an API - a set of commands that you can invoke.

Sometimes these terms can be mixed together. For example, you have a server application (for example, TFS). It has an API with it, and this API is implemented as a library. But this library is just the middle layer between you, and not the one who makes your calls. But if the library itself contains all the action code, we cannot say that this library is an API.

+14
Sep 09 '10 at 16:48
source share

A library contains reusable pieces of code.

These reusable library codes are associated with your program through APIs (application programming interfaces). That is, the API is an interface to the library through which reusable codes are associated with the application program.

enter image description here

For example, in procedural languages ​​such as C, the math.c library contains implementations of a mathematical function such as sqrt , exp , log , etc. It contains a definition of all these functions.

This function can be referenced using the math.h API, which describes and prescribes expected behavior .

+13
Jan 19 '15 at 15:32
source share

I think Library is a collection of all classes and functions that can be used from our code to facilitate our task. But the library may contain some of its private functions for its use, which it does not want to disclose.

API is part of the library that is provided to the user. Thus, regardless of the documentation the library has, we call it API Documentation , since it contains only the classes and functions that we have access to.

+10
Sep 06
source share

we must first define the interface ...

Interface : this is the means by which 2 "things" talk to each other and exchange information. β€œthings” can be (1) human or (2) working code of any type (e.g. library, desktop application, OS, web service ... etc.).

if a person wants to talk with the program that he needs Graphical user interface (GUI) or command line interface (CLI). both are types of interfaces that people (but not programs) would like to use.

if, however, any executable code (of any type) wants to talk to another executable code (of any type), it does not need or does not need a graphical or command line interface, it will most likely need an Application Programming Interface (API).

to answer the original question about the post: the library is a type of executable code, and the API is the way this code works with other executable codes.

+3
Nov 20 '15 at 17:24
source share

In a clear and concise language

Library: collecting all classes and methods stored for reuse

API: part of a library of classes and methods that can be used by the user in his / her code.

0
Oct. 12 '13 at 13:55
source share

According to my point of view, no matter what functions are available for invoker, we can call api in a library file, a library file that has some private functions, we can not access them.

0
Dec 29 '15 at 6:41
source share



All Articles