How back-end web frameworks work?

Updated Apr 06, 2022 ⤳ 4 min read

Backend web frameworks or  HTTP-based frameworks are software frameworks you can use to build functionalities like CRUD interfaces, authentication systems, APIs, integrations, etc.

Frameworks come in the form of pre-written code you can customize and extend.

A web framework is like the first course of bricks in a wall, which gives direction to the development process.

A backend framework isn’t like a library that you include in your code.

It is the code, and you only extend its functionality.

On the other hand, you add code to the framework’s code and gradually shape it into an application. 

This phenomenon is called Inversion of Control or IoC.

How frameworks power your application

When a request hits the web server (a user visits a page), the web server evaluates the request. 

If the request is valid and the web server finds a match for the requested URL, it proceeds to prepare a response.

If the requested resource is a static file, the web server fetches it from the file system and returns it.

However, if the request requires some dynamic processing, such as an API request, it forwards it to the respective handler.

Based on your web server configurations, if the requested URL is for your app, it forwards the request to your app’s entry file

The entry file is known as Front Controller or FC.

This is where a request lifecycle begins.

The front controller bootstraps the framework (your app) and makes it ready to handle client requests.

Once the application is ready, the framework’s router dispatches the request to the respective controller to populate the proper response and returns it to the waiting webserver.

Consequently, the web server returns it to the user.

Controllers are functions you add to the framework’s code to handle requests based on the URL patterns.

For example, you write one controller to return inventory data and another to get order information from the database.

What frameworks to use

Sometimes, the popularity of a programming language depends on the number of successful frameworks developed in that language.

The most popular web-based frameworks are:

  • Laravel (in PHP)
  • Symfony (in PHP)
  • Ruby on Rails (in Ruby)
  • Django (in Python)
  • Express.js (in JavaScript)

Choosing a framework shouldn’t be a difficult decision. 

Usually, you choose a framework in your programming language of choice.

Full-featured frameworks (like those mentioned above) provide essential components any server-side application needs, such as:

Full-featured frameworks handle
  1. Managing HTTP requests & responses
  2. Routing (for dispatching requested URLs to their respective controllers)
  3. Built-in authentication & authorization mechanisms
  4. Database management
  5. Event management
  6. Session and Cache management
  7. Templating
  8. File storage
  9. Testing

For smaller projects, you can use a micro-framework.

Micro-frameworks are lighter than a full-featured framework, but they provide the bare minimum features you need to develop your backend app.

Micro-frameworks are well-suited for rapid prototyping, making web APIs, web services, or even a complete project depending on its size.

Here are three of the most popular micro-frameworks in the market:

  • Lumen (in PHP)
  • Flask (in Python)
  • Sinatra (in Ruby)

Disclaimer: This post may contain affiliate links. I might receive a commission if a purchase is made. However, it doesn’t change the cost you’ll pay.

`