What is the difference of API, library and Framework?

Asked

Viewed 64,346 times

223

They seem to me very close terms and eventually I see texts that exchange one for the other, as if in some situations their definitions overlap.

What would be the technical definitions to distinguish what is API, library and Framework?

In which situations it is allowed to exchange the terms without hurting its technical definition?

6 answers

195


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.

Lib X FW

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.

  • 7

    It’s true, Toolkit and SDK can also get into the "mix" of these concepts. I liked that you cited.

  • 6

    I accepted that answer because I consider it the most didactic.

  • 5

    +1 for the "Lifestyle"

  • 2

    @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 ?

  • 3

    @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.

82

API

API(Application Programming Interface - Interface between Application and programming) is a set of instructions and programming patterns for access to a software application. A software company launches its API to the public so that other software creators can develop products powered by this service.

Take as an example the Mercadolivre, which makes your API available so that website developers could have easier access to information about your products. With the use of the API, an independent website can post links directly to products from Mercadolivre, with updated prices and an option that allows immediate purchase.

With Apis, apps chat with each other without knowledge and/or user intervention. When you purchase cinema tickets online, the ticket site uses an API to send your credit card information to a remote application that checks whether the data is proceeding. As soon as the payment is confirmed, the remote application sends a reply to the ticket site releasing the issuance of purchased tickets.

Another example is the Windows API gives developers access to things like:

  1. File system(ie Createfile, Deletefile, Getfilesize),
  2. Device Management(ie Setupdienumdeviceinfo, Dishowupdatedevice),
  3. Windows registry(ie Regcreatekeyex, Regdeletekeyex),
  4. Shell(ie Createprofile, Getallusersprofiledirectory, Shellexecuteex).

inserir a descrição da imagem aqui

Library

A Library is a collection of implementations(ie function, classes, procedures), which has a well-defined interface by which the behavior is invoked. In addition, the behavior is provided for reuse by several independent programs. A program invokes the behavior provided by the library through a language mechanism. What distinguishes the call as being to a library vs another function in the same program, is the way the code is organized in the system.

inserir a descrição da imagem aqui

Framework

A framework is often a layered structure, indicating what type of programs can or should be constructed and how they interrelate. Some system structures also include actual programs, specify programming interfaces, or offer programming tools to use the Frameworks.

inserir a descrição da imagem aqui

Note: Image taken from the site Dot Net Tricks

A Framework can be for a set of functions within a system and how they interrelate, the layers of an operating system, the layers of an application subsystem, how communication should be standardized at some level of a network, and so on.

  • 3

    The Windows API link was very timely

45

The formal definitions are already in other responses, so I’m going to try a more pragmatic approach.

API in general is the set of interfaces, classes and methods available to you to use in a framework, tool or service. A REST or SOAP Web Service that has a set of available services can be called an API. The JEE architecture standard consists of several Apis (Servlets, EJB, etc.). Each Javadoc documents the API of the respective project.

Think of a Framework as a prefabricated structure that you "buy", assemble the little pieces according to the manual, fill the brains with what is missing and build what you need. Each will serve different scopes, but all will try to solve common problems that the developer faces. For example, a web framework will provide you with the means to solve all the most common points of a web architecture: data listing, internationalization, formatting, control logic, competition, scalability and so on.

On the other hand, there is also the concept of work framework that goes beyond the technology itself. It proposes a form of work based on certain concepts. Examples are RUP and Scrum, which can be called process frameworks. The concept of Mapreduce used in Big Data is also a type of framework that defines how parallel and distributed processing is done. From the concepts, then you can build Apis, tools, libraries and even frameworks that implement the concepts involved.

One library could be well defined as a set of classes or routines that assist in common tasks. They say all good programmers have their own set of libraries.

Finally, consider that all these terms are interconnected:

  • An API can be defined by an institution (W3C, JCP) and implemented by tools, frameworks and libraries.
  • A framework can implement and make available one or more Apis and use multiple internal or third-party libraries.
  • A library has its own API and can work together with multiple frameworks.

In theory, it is wrong to use terms interchangeably, as there are subtle differences depending on context. In practice this gets a bit blurred, especially when the user does not know in detail the library, tool or framework.

Even so, one can say without any problem that used the Spring framework formatting API or even the library of useful routines that are present Spring framework to work with lists (Collections).

Abstract: if a framework implements an API, I can say both that I am using the framework and the API, because in this case they are the same "person".

  • 1

    So every API is a library? For example Jodatime is a library to work with dates and at most communicates with other libraries but does not serve to implement a service, and Servlets are libraries to use the web framework, so an API?

  • 3

    @Math Every library is an API. Servlets are not libraries, it is an API because it consists of a set of interfaces and classes that you implement to build your application. But speaking of Jsps we can say that the Taglibs are common-use libraries that imply a JEE-defined API or even additional Taglibs defined by third parties.

  • 2

    A library has an API (Application Programming Interface). The same way as a program has a user interface, but the program is not just your screen; a library has an interface (function names, parameter types, etc.) to access the internal functionality, but the library is not the API. Sometimes people define a common API to be used by multiple libraries, for example.

38

According to Wikipedia:

API

API, of Application Programming Interface (or Application Programming Interface) is a set of routines and standards established by software for the use of its functionality by applications that do not intend to engage in details of software implementation, but only use its services

Framework

A framework (or framework), in software development, is an abstraction that unites common codes between several software projects providing a generic functionality. A framework can achieve a specific functionality, by configuration, during the programming of an application. Unlike libraries, it is the framework that dictates the control flow of the application, called Control Inversion.

But you’ve surely searched for the definitions.

One API is basically an Application translated into a targeted service, through which other Applications, complete or not, may exist. All this independent of the language because, like all Interface (non-visual, of course), its function is to allow the programmer to understand an architecture without knowing its implementation.

Notice I didn’t list the definition of Library because it is directly related to a Framework, even if it may not be part of a framework, with all its rules and guidelines.

Often a library is just a group of multiple file functions that exchange solutions to solve a specific problem (see below).

And a Framework can be classified into two groups: those of specific domain and so-called full-stack that are nothing more than several frameworks specific domain part of something bigger, and can even share dependencies.

And every framework, whatever it is, has its own API, with the signatures of its methods which, as said, allows the programmer to use it without opening the code.

Ideally one should not mix the definitions to not cause confusion to the obvious interlocutor, but, for example, use the term framework both for the specific field and full stack is harmless because they are frameworks anyway.

A simple library is also a framework, but a specific domain, a term not always known that can result in an erroneous but harmless statement.

API is different. Although intrinsically related it represents a completely different thing.

  • 2

    They raised some questions by reading your text, every API is a library, however not every library is an API? An API then would be a library that interfaces two services? And a Framework is a set of libraries?

  • 3

    I don’t see an API as a library but yes, every library has its API, even though many "programmers" (those guys who think they’re programming) don’t see it. And yes, a framework is a set of libraries, all encoded in the same pattern, structured in the same way, rewritten under the same standardized model and so on.

35

API

Application Programming Interface or Application Programming Interface. You will use an API to access an external program or service. For example: you can create a third-party app for Facebook, Twitter, or even Stackoverflow using their respective Apis. There are operating system features, such as Windows and Android, which are also available via Apis.

Library

Used for something that meets a specific need. For example, convert HTML to PDF, ORM (Object Relational Mapping), among many others.

Framework

Used for something much wider. Think of the amount of things that a framework web makes: routes, orm, session, database versioning, HTML generation, user management, among many other things. In some cases, frameworks are made from several libraries working together.

Still on API

As stated in the other responses, both libraries and frameworks usually have an API, i.e., a documented interface for programmers to be able to use. In this case you are using both the library/framework as its respective API. As an example see the documentation of this Activerecord library API.

19

Summary explanation:

API

It’s for integrating systems. Someone provides an API so you can integrate your system with the system that provided the API. Or you create and provide an API if you want someone to integrate a system with yours. In general, it can be a set of classes or ways to access a Rest or Soap webservice.

Library

Set of functions grouped for the same purpose. It’s like a Swiss Army knife, you use what you need, when you need it.

Framework

It is a skeleton to build applications. You must obey the folder structure and follow the practices defined by the framework.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.