To complement, help or confuse a little more :) and be slightly dissonant. Terms can be defined differently depending on the context.
I went to look at the definition found on Wikipedia in English for the terms API, Library and Framework. "Just for a change" in English is a better definition.
API
There it becomes clear that an API is a more abstract concept that defines ways to perform a specific task. It’s the way your code relates to a library. Some responses give the impression (not necessarily claim) that API is for accessing external services to the application, and often this is true. If it were always true, "how to manipulate a string" wouldn’t be an API, which is. A lot of people use the term API for something else related that is webservices or something similar, where you obviously have an API, but the provision of services is not the API itself.
In a way we can say that the API is the documentation that determines how a programmer can accomplish a task through a library. Of course there is no mandatory link with the documentation. It is possible to have an API (nut) without documentation. And the effective documentation of a library will be close but not necessarily equal to the API. The API is a set of rules to perform a task. It deals with possible behaviors. It is the contract.
An API is usually stable, especially when it is free to use publicly. Although unusual it may have parts documented as unstable (mutable), which requires great care in its use.
In some cases an API can document some details of how the implementation should be to ensure that some objectives are achieved.
The API is one more specification and not an implementation.
Library
The library usually is a real implementation of the rules of an API. So it’s more concrete. Like the API, you don’t need to know the details of the implementation to use it. The library must always respect API rules, but does not need to have its implementation stable. The library is usually self-sufficient.
A library can contain public implementations that are not part of the API. Using them can bring risk.
You call a library. It’s a tool. You use what you need.
So far no reply has dealt with the term library as a way of organizing binary codes for use with applications. A library is also an executable file containing a set of functions to perform several tasks. .dll
or .so
are library files for dynamic link in the application. .lib
or .a
are library files for static connection in the application.
You can have a library of manipulation strings, of regular expressions, data collections, file manipulation, access to a database, image manipulation, etc.
Libraries can be external, which is the case with web services. This is a common way nowadays to prevent piracy, since many applications are web. It may have some advantages, but it also has many disadvantages.
Framework
A framework is usually a set of libraries to be able to perform a larger operation. It is common a framework encapsulate API behaviors into more complex implementations, allowing their use more flexibly, often through extensions, settings and control inversions. How a layer can be considered on top of the API can eventually simplify it in a sense. It usually gives consistency to a set of libraries (too bad the opposite happens in some cases).
The framework usually "take care" of your application leaving "doors" for you to access, which is important for your goal. It is common to have a great interdependence between its components. For these two reasons, framework can become a burden when it is not well done, or is not suited to what the programmer needs, or when the programmer does not know well how to use it. What is very common happen one or more of these situations.
A framework calls you. It’s a lifestyle. Your project commits to it.
Frameworks can be understood as development platforms. They have gaps that must be filled by the programmer to work as your need. It can be seen as a skeleton of an application. They are often confused, right or wrong, as a set of classes.
Sometimes the term is used to determine a set of binary code library files, or sources, or even other resources for the application that are related.
Examples are GUI systems, web operations systems, some Orms, a set of standard libraries of a programming language, implementation of an MVC standard, etc.
Sometimes a library is or becomes so complex that it becomes one framework. If this is good or bad I leave it to you to decide.
Toolkits and Sdks
You haven’t asked but there are still toolkits which may be confused with frameworks but work more freely, they’re more like libraries working together, but in a traditional way where you call what you need.
There are still Sdks. Software Development Kits may take the form of toolkits or of frameworks and provide everything you need to program on top of a platform (operating system, database, application, etc.). These kits often include additional tools in addition to libraries as well as documentation and code examples that help you use the library properly.
Completion
Most of the time the terms can be interchangeable without causing much trouble. Everyone understands these three things as a set of codes ready to achieve some goal (even if that’s not exactly right in all three cases).
But when you’re defining something more formal, when you explain to someone details of a project, it’s best to use the right terms to give them a better understanding. Of course, if the caller does not know the correct terms, the conversation is truncated anyway. Then you send the subject to read this :)
Some settings and pictures I took of those responses in the OS.
It’s true, Toolkit and SDK can also get into the "mix" of these concepts. I liked that you cited.
– Math
I accepted that answer because I consider it the most didactic.
– Math
+1 for the "Lifestyle"
– Josh
@bigown I am trying to understand the actual application of this term, and not to open another question here I am: where the API is in the code ? If there is a link in my question... Like, it is a part of the code, it is the code + documentation, which make up the API ?
– MagicHat
@Magichat Roughly speaking, what is public in code (done with awareness) ends up being part of the API, after all it is a public contract for use. But if it is not documented we can not consider as the API, can be public by chance.
– Maniero