DEV Community

Supratim
Supratim

Posted on

Please ELI5: Frameworks vs Libraries vs API

Can anyone explain me, what are frameworks,libraries and api's. What are the difference between them and how they are helpful? in the development area with some examples.

Top comments (4)

Collapse
 
pp profile image
Paweł Ludwiczak

I'm not an expert but I'll try:

  • Framework is like Lego. It provides you pieces you can use to build something.
  • Library is a set of very specific Lego pieces. Pieces that didn't exist in your original set of Lego.
  • API is when you have built a house with Lego and you need Lego guys to live there but you don't want to teach them how to behave (lol this metaphor isn't ideal probably :D)... BUT there's someone out there who built entire city with Lego, including Lego guys. This person is letting you borrow their trained Lego guys and use in you own project...
Collapse
 
sup profile image
Supratim

OMG!Thank you very much! The example was very helpful 😄

Collapse
 
kspeakman profile image
Kasey Speakman • Edited

Framework

A framework uses the Hollywood Principle - "Don't call us, we'll call you." You have to integrate your code into a framework. Your code has to conform to the framework structure. Usually meaning it has to implement specific methods or properties.

Advantages

  • It provides an opinionated mix of technology to accomplish some common scenarios for you.
    • Can allow you to develop an app quickly.

Disadvantages

  • It may not cover your specific needs, and you may have to work around the framework to accomplish them.
  • It often does extra things you do not need but still have to deal with.
  • Significant framework updates can be very expensive for you.
    • Because your app is coupled to the framework in so many places.
    • Often apps will choose to stay at an old framework version instead of upgrading.
  • Cannot switch frameworks -- it typically means rewriting the application.

Library

A library performs a specific function, and you call it for that function, and then move on with the rest of your code. When building your app from libraries...

Advantages

  • You retain control over the structure of your application, making it more adaptable to new situations.
  • It is relatively easy to add new functionality by integrating new libraries.
  • Significant updates to a library tend to affect only small portions of a code base.
    • You can usually accomplish major upgrades of a library.
  • Can change libraries if a better alternative arises.

Disadvantage

  • You are responsible for developing the structure of the app.
    • This takes time and iteration.
    • Whereas a framework would decide this up front for you.

API

API is an overloaded term. Generally speaking, it just refers to any library or framework's surface area... the exposed objects, methods, etc. that you are supposed to use. It is the dev equivalent of a user interface.

Web API

More specifically, a "web API" is typically a service that runs on the back-end to perform functions that the (usually Javascript) front-end is not capable of doing directly. So the front-end makes HTTP calls to the API service, which performs the functionality on the server. Examples: saving to database, sending email. Some web APIs are public, meaning anyone can call them to get data.

Collapse
 
sup profile image
Supratim

Thank you!!It was very helpful :)