designwithfocus

Back end & development

Framework vs Library vs API: Who Calls Whom

By Design With Focus Team 7 min read
Three labeled boxes for a framework, a library, and an API

Short answer

A library is code you call, a framework calls your code, and an API is the contract for talking to a program. MDN names inversion of control as the library-versus-framework line. An API can live in the browser or on a third-party service. The three words name different jobs.

Last verified against the sources listed below.

Key takeaways

  • MDN says a library is usually files of functions you attach to a page, and you stay in control.
  • The same page says a framework inverts control: the framework calls your code.
  • MDN's glossary calls an API a set of features and rules for software to interact with a program.
  • Browser APIs are not part of the JavaScript language. They are built on top of it.
  • React is a UI library on MDN's frameworks page. Next.js docs call Next.js a React framework.

A framework vs library vs api question is about who calls whom. MDN’s web API lesson says a JavaScript library is usually one or more files of functions you attach to a page. You call those functions. A framework, on that same page, is the next step up: you install it and write the application inside it.

The lesson names the difference as inversion of control. When you call a library method, you are in control. With a framework, control is inverted: the framework calls your code. An API is not that same choice.

MDN’s glossary calls an API a set of features and rules inside a program that let other software interact with it, as opposed to a human user interface. Your code calls that contract.

You can meet all three in one afternoon. The browser gives you APIs. A chart helper can be a library you call. A UI framework can call the components you wrote.

The words stay useful only if you keep those jobs apart. One download can include more than one of them.

What is a library?

A library is code you call for a job you do not want to write from scratch. MDN describes library files as custom functions that speed up or enable common work. The examples on the web API page are jQuery, Mootools, and React. You add the file, then you decide when to use it.

MDN’s frameworks introduction is more specific about React. It says React is not itself a framework. It is a library for rendering UI components, used with other libraries to make an application. React’s learn page shows the shape of that library: components are JavaScript functions that return markup.

That is the “you call it” test. Your script creates a component, passes data, and handles a click by passing a function down. React updates the screen when state changes. Your code still decides which component runs and what the click should do.

An SVG to JSX tool emits that kind of component. It does not install a framework for you.

What is a framework?

A framework calls your code and sets the shape of the application. MDN’s web API lesson says frameworks tend to be packages of HTML, CSS, JavaScript, and other technologies that you install and then use to write an application from scratch. Angular and Ember are the examples there. The inversion-of-control line is the part to remember: the framework calls you.

The frameworks introduction puts it another way. A framework is a library that offers opinions about how software gets built. Those opinions make an application more predictable, which is why teams use them on large interfaces. The same page says a small portfolio with little interaction may not need a framework at all.

Next.js docs show a framework wrapped around a library. They call Next.js a React framework for full-stack web applications. You still write React components. Next.js supplies routing, bundling, and the rest of the application shell.

Vue’s introduction calls Vue itself a JavaScript framework, and it says you can start by enhancing static HTML or grow into a full application. In both cases the framework is the thing that owns the application structure.

What is an API?

An API is the set of features other software uses to interact with a program. The glossary says you can think of it as a contract between the application that offers the API and the callers, which might be other software or hardware. In web development, MDN says an API is generally methods, properties, events, and URLs a developer uses from an app.

Client-side JavaScript has many of these, and they are not part of the language. MDN splits them into browser APIs and third-party APIs. A browser API ships in the browser. The DOM API creates and changes HTML.

Fetch loads data without reloading the whole page. Canvas and WebGL draw. Geolocation reads a location the device can provide.

A third-party API is one you go and get. The lesson’s map example is the Google Maps API: constructs for placing a map on your site and asking the service for information. Your page calls that API. The API does not become your framework unless you also adopt a toolkit that takes over the rest of the app.

How do the three compare?

The caller is the difference, and the table keeps the definitions next to each other. One product can include more than one row. Next.js is a framework, React is the library it expects, and both expose APIs you read in their docs.

Library Framework API
Who calls whom You call its functions It calls your code You use its features to reach a program
MDN’s short picture Files of functions you attach A package you write the app inside A contract of methods, properties, events, or URLs
Control You stay in control Inversion of control Neither word replaces the contract
Examples MDN names jQuery, Mootools, React Angular, Ember DOM, Fetch, Geolocation, Google Maps
What it is not Not the whole application shell Not required for a small static page Not the same thing as a framework

Software development is the wider job of choosing these pieces and wiring them. The caller test works on a server handler too.

Back end development is where many third-party and server APIs live, even though the MDN lesson above is about the browser side. The “who calls whom” test still works on the server: your handler calls a library, or the framework calls your handler when a request arrives.

Which do you reach for?

Reach for an API when a platform already has the feature and you only need the contract. Reading a location, drawing on a canvas, or fetching JSON are API calls. You do not install a new application structure to use them. You do need to know the entry object, and some APIs ask the user before they run.

Reach for a library when you want a helper and you want to keep the surrounding page. A React component that renders one widget is that shape, as long as you are the one deciding where it mounts. Reach for a framework when the interface is large enough that you want the tool to call your components and enforce a structure. MDN’s warning still stands: a quiet brochure site can stay as HTML, CSS, and a short script.

What do people mix up?

People call every download a framework. MDN’s own React note exists because of that habit: React is a library, and a framework such as Next.js is what you add when you want the application shell. Saying “the React framework” for the library alone skips the inversion-of-control test.

People also treat an API as a product category you install once. The glossary’s contract can be three lines on document, or a remote map service. Both are APIs. Only the second one is a network dependency.

Naming the caller, the library, and the contract separately keeps a design review shorter than a stack of brand names. The brand is a weaker test than who calls whom.

Frequently asked questions

Which examples does MDN give for libraries and frameworks?

The introduction to web APIs lists jQuery, Mootools, and React as libraries: files of functions you can attach to a page. It lists Angular and Ember as frameworks: packages you install and then use to write an application. A later frameworks lesson adds that React is technically a library for rendering UI components, and that people often pair it with other libraries. Those names are examples, not a ranking.

Where do you enter a browser API?

MDN's web API lesson says APIs are based on objects, and that you should know the entry point. For the Web Audio API, that entry is an AudioContext. For the DOM, features hang off the document or an element. For Canvas, you call getContext on a canvas element and then draw through the context object. You call those objects. They do not replace your whole application.

What is a third-party API in the browser?

MDN says third-party APIs are not built into the browser. You retrieve their code or information from the web. The lesson's example is the Google Maps API, which supplies constructs for showing a map and asking the service for data. A browser API such as Geolocation is the other kind: it is already in the browser, and it can ask the user before it shares a location.

Does a framework ban plain scripts?

MDN's frameworks introduction says a personal portfolio with little interaction may not need a framework or the JavaScript that comes with it. The web API lesson still applies on that page, because the DOM and events are available to an ordinary script. A framework is the step you take when you want its structure to call your components. A small page can stay with a library function or with no library at all.

How does Vue describe itself next to this split?

Vue's introduction calls Vue a JavaScript framework for user interfaces, and a progressive framework you can adopt in steps. It does not use the phrase inversion of control. The MDN page is the one that uses that phrase for the library-versus-framework difference. Vue's own page is still useful here because it shows a framework that can enhance static HTML or cover a whole application.

Sources