DEV Community

Cover image for Behind the Scenes: Exploring Powerful Backend Frameworks
Burak Boduro─člu
Burak Boduro─člu

Posted on

Behind the Scenes: Exploring Powerful Backend Frameworks

Contents ­čôľ


Django:

Django Logo

  • Description: Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. It follows the Model-View-Controller (MVC) architectural pattern and comes with built-in tools for handling tasks such as database migrations, user authentication, and more.
  • Key Features:
    • Object-Relational Mapping (ORM) for database interactions.
    • Admin interface for easy content management.
    • Django REST Framework for building APIs.
    • Built-in security features.
  • Example:
# Install Django
pip install Django
Enter fullscreen mode Exit fullscreen mode
# Create a Django project
django-admin startproject myproject
cd myproject
Enter fullscreen mode Exit fullscreen mode
# Create a Django app
python manage.py startapp myapp
Enter fullscreen mode Exit fullscreen mode
# Define Models (myapp/models.py)
from django.db import models

class Book(models.Model):
    title = models.CharField(max_length=200)
    author = models.CharField(max_length=100)
    published_date = models.DateField()

    def __str__(self):
        return self.title
Enter fullscreen mode Exit fullscreen mode
# Migrate the Database
python manage.py makemigrations
python manage.py migrate
Enter fullscreen mode Exit fullscreen mode
# Create Views (myapp/views.py)

from django.shortcuts import render
from django.http import HttpResponse
from .models import Book

def index(request):
    books = Book.objects.all()
    return render(request, 'myapp/index.html', {'books': books})
Enter fullscreen mode Exit fullscreen mode
# Create Templates (myapp/templates/myapp/index.html)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Book List</title>
</head>
<body>
    <h1>Book List</h1>
    <ul>
        {% for book in books %}
            <li>{{ book.title }} by {{ book.author }} (Published on {{ book.published_date }})</li>
        {% endfor %}
    </ul>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode
# Run the Development Server
> python manage.py runserver
Enter fullscreen mode Exit fullscreen mode

Express.js:

Express Logo

  • Description: Express.js is a minimal and flexible Node.js web application framework that provides a robust set of features to develop web and mobile applications. It is designed to be simple and unopinionated, allowing developers to structure their applications as they see fit.
  • Key Features:
    • Middleware support for handling HTTP requests.
    • Routing system for defining endpoints.
    • Template engines for dynamic content.
    • Integration with Node.js ecosystem.
  • Example:
# Create a new directory and navigate into it:
> mkdir myexpressapp
> cd myexpressapp

# Initialize a new Node.js project
> npm init -y

# Install Express
> npm install express
Enter fullscreen mode Exit fullscreen mode
const express = require('express');
const app = express();
const port = 3000;

// Define a simple route
app.get('/', (req, res) => {
  res.send('Hello, Express!');
});

// Start the server
app.listen(port, () => {
  console.log(`Server is running at http://localhost:${port}`);
});
Enter fullscreen mode Exit fullscreen mode
# Run your Express application
> node app.js
Enter fullscreen mode Exit fullscreen mode

Ruby on Rails:

Ruby on Rails Logo

  • Description: Ruby on Rails, often referred to as Rails, is a web application framework written in Ruby. It follows the convention over configuration (CoC) and don't repeat yourself (DRY) principles, aiming to make development more straightforward and efficient.
  • Key Features:
    • Convention-based MVC architecture.
    • ActiveRecord for database interactions.
    • Scaffolding for quick prototyping.
    • RubyGems for easy integration of third-party libraries.
  • Example:
# Create a new Ruby on Rails application
> rails new myrailsapp
> cd myrailsapp

#Generate a model and migrate the database
> rails generate model Book title:string author:string 
published_date:date
> rails db:migrate

# Generate a model and migrate the database:
> rails generate controller Books index
Enter fullscreen mode Exit fullscreen mode
class BooksController < ApplicationController
  def index
    @books = Book.all
  end
end
Enter fullscreen mode Exit fullscreen mode
# Create Route
Rails.application.routes.draw do
  resources :books, only: [:index]
  root 'books#index'
end
Enter fullscreen mode Exit fullscreen mode
# Create Views
<!DOCTYPE html>
<html>
<head>
  <title>Book List</title>
</head>
<body>
  <h1>Book List</h1>
  <ul>
    <% @books.each do |book| %>
      <li><%= "#{book.title} by #{book.author} (Published on #{book.published_date})" %></li>
    <% end %>
  </ul>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode
rails server
Enter fullscreen mode Exit fullscreen mode

Flask:

Flask Logo

  • Description: Flask is a lightweight and easy-to-extend Python web framework. It is designed to be simple and modular, allowing developers to choose the components they need for their applications. Flask is often used for small to medium-sized projects and APIs.
  • Key Features:

    • Microframework for simplicity.
    • Jinja2 templating engine.
    • Werkzeug WSGI toolkit.
    • Extension support for adding functionality.
  • Example:

# Create a new directory and navigate into it
> mkdir myflaskapp
> cd myflaskapp
Enter fullscreen mode Exit fullscreen mode
# Create a virtual environment (optional but recommended)
> python -m venv venv
Enter fullscreen mode Exit fullscreen mode
# Activate the virtual environment

# On Windows
> venv\Scripts\activate

# On macOS/Linux
> source venv/bin/activate

# Install Flask
> pip install Flask
Enter fullscreen mode Exit fullscreen mode
# Create your Flask application (app.py)
from flask import Flask, render_template

app = Flask(__name__)

# Sample data
books = [
    {"title": "Book 1", "author": "Author 1", "published_date": "2022-01-01"},
    {"title": "Book 2", "author": "Author 2", "published_date": "2022-02-01"},
    {"title": "Book 3", "author": "Author 3", "published_date": "2022-03-01"},
]

@app.route('/')
def index():
    return render_template('index.html', books=books)

if __name__ == '__main__':
    app.run(debug=True)

Enter fullscreen mode Exit fullscreen mode
# Create templates folder and HTML file (templates/index.html))

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Book List</title>
</head>
<body>
    <h1>Book List</h1>
    <ul>
        {% for book in books %}
            <li>{{ book.title }} by {{ book.author }} (Published on {{ book.published_date }})</li>
        {% endfor %}
    </ul>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode
# Create URLs (myapp/urls.py)

from django.urls import path
from .views import index

urlpatterns = [
    path('', index, name='index'),
]
Enter fullscreen mode Exit fullscreen mode
# Run your Flask application
> python app.py
Enter fullscreen mode Exit fullscreen mode

Spring Boot:

Spring Boot Logo

  • Description: Spring Boot is an extension of the Spring framework that simplifies the development of Java-based applications. It provides convention-over-configuration and opinionated defaults for building production-ready Spring applications with minimal effort.
  • Key Features:

    • Auto-configuration for common use cases.
    • Embedded web server support.
    • Spring Data for data access.
    • Spring Security for authentication and authorization.
  • Example:

# Create a new directory and navigate into it
mkdir myspringbootapp
cd myspringbootapp
Enter fullscreen mode Exit fullscreen mode
- Create a new Spring Boot application using Spring Initializr:
- Visit Spring Initializr in your web browser and configure the project as follows:
 - Project: Maven Project
 - Language: Java
 - Spring Boot: Select a recent version
 - Group: com.example
 - Artifact: myspringbootapp
 - Dependencies: Spring Web
 - Click "Generate" to download the project zip file.
Enter fullscreen mode Exit fullscreen mode
# Extract the downloaded zip file and navigate into the project directory
unzip myspringbootapp.zip
cd myspringbootapp

# Open the project in your favorite Java IDE (e.g., IntelliJ IDEA, Eclipse)
Enter fullscreen mode Exit fullscreen mode
/*
Edit the src/main/java/com/example/myspringbootapp/MyspringbootappApplication.java file:

Replace its content with the following:
*/
package com.example.myspringbootapp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
public class MyspringbootappApplication {

    public static void main(String[] args) {
        SpringApplication.run(MyspringbootappApplication.class, args);
    }

}

@RestController
class MyController {

    @GetMapping("/")
    String home() {
        return "Hello, Spring Boot!";
    }
}

Enter fullscreen mode Exit fullscreen mode
# Run Spring Boot Application
./mvnw spring-boot:run

# Visit http://localhost:8080 in your web browser, and you should see the message "Hello, Spring Boot!"
Enter fullscreen mode Exit fullscreen mode

Laravel:

Laravel Logo

  • Description: Laravel is a PHP web application framework known for its elegant syntax and developer-friendly features. It follows the Model-View-Controller (MVC) pattern and includes tools for tasks like database migrations, routing, and unit testing.
  • Key Features:
    • Eloquent ORM for database interactions.
    • Blade templating engine for views.
    • Artisan command-line tool for task automation.
    • Laravel Mix for asset compilation.

ASP.NET Core:

ASP.NET Core Logo

  • Description: ASP.NET Core is a cross-platform, high-performance framework for building modern, cloud-based, and internet-connected applications. Developed by Microsoft, it supports multiple programming languages, including C# and F#.
  • Key Features:
    • Cross-platform support (Windows, macOS, Linux).
    • Middleware for handling HTTP requests.
    • Dependency injection for managing components.
    • Integrated support for WebSockets and SignalR.

FastAPI:

FastAPI Logo

  • Description: FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.7+ based on standard Python type hints. It is designed to be easy to use and to provide automatic interactive documentation.
  • Key Features:
    • Fast and asynchronous framework.
    • Automatic data validation using Python type hints.
    • OpenAPI and JSON Schema support.
    • Dependency injection system.

AdonisJS:

AdonisJS Logo

  • Description: AdonisJS is a Node.js web framework that follows the Model-View-Controller (MVC) pattern. It provides a set of conventions and tools to help developers build scalable and maintainable applications.
  • Key Features:
    • Lucid ORM for database interactions.
    • Edge templating engine.
    • Command-line tools for project management.
    • Middleware support for HTTP request handling.

Hapi.js:

Hapi.js Logo

  • Description: Hapi.js is a rich framework for building applications and services in Node.js. It is known for its configuration-driven approach, making it highly customizable. Hapi.js is often used for building RESTful APIs.
  • Key Features:
    • Configuration-driven architecture.
    • Built-in input validation and authentication.
    • Plugin system for extending functionality.
    • Support for handling real-time events.

Phoenix (Elixir):

Phoenix (Elixir) Logo

  • Description: Phoenix is a web framework for the Elixir programming language. It follows the model-view-controller (MVC) pattern and is known for its performance and real-time capabilities, making it suitable for building scalable and reliable applications.
  • Key Features:
    • Channels for real-time communication.
    • Ecto for database interactions.
    • Productivity features like code reloading.
    • Fault-tolerant and distributed architecture.

NestJS:

NestJS Logo

  • Description: NestJS is a TypeScript-based Node.js framework that combines elements of object-oriented programming, functional programming, and reactive programming. It is built with modularity in mind and is often used to develop scalable server-side applications.
  • Key Features:
    • Decorators for defining modules and controllers.
    • Dependency injection system.
    • Support for WebSockets and GraphQL.
    • Middleware and guard functions for request handling.

Ktor:

Ktor Logo

  • Description: Ktor is a Kotlin-based framework for building asynchronous servers and clients. It is designed to be simple, lightweight, and expressive. Ktor is particularly popular for building microservices and RESTful APIs.
  • Key Features:
    • Coroutine-based asynchronous programming.
    • Extensible routing system.
    • Content negotiation for handling different data formats.
    • Integration with Kotlin features and libraries.

Rocket (Rust):

Rocket (Rust) Logo

  • Description: Rocket is a web framework for the Rust programming language. It focuses on ease of use, developer productivity, and type safety. Rocket follows a declarative approach, making it concise and expressive.
  • Key Features:
    • Type-driven request handling.
    • Automatic route generation.
    • Powerful macro system for metaprogramming.
    • Integration with Rust's ownership system.

Gin:

Gin Logo

  • Description: Gin is a web framework written in Go (Golang). It is known for its minimalistic design and high performance, making it a popular choice for building RESTful APIs and web applications in Go.
  • Key Features:
    • Fast HTTP router with flexible routing.
    • Middleware support for extensibility.
    • JSON validation and rendering.
    • Structured logging and error handling.

Actix Web:

Actix Web Logo

  • Description:Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust
  • Key Features:
    • Supports HTTP/1.x and HTTP/2
    • Streaming and pipelining
    • Powerful request routing with optional macros
    • Full Tokio compatibility
    • Keep-alive and slow requests handling
    • Client/server WebSockets support
    • Transparent content compression/decompression (br, gzip, deflate, zstd)
    • Multipart streams
    • Static assets
    • SSL support using OpenSSL or Rustls
    • Middlewares (Logger, Session, CORS, etc)
    • Integrates with the awc HTTP client
    • Runs on stable Rust 1.68+

axum:

  • Description: "axum" is a web application framework that focuses on ergonomics and modularity.
  • Key Features:
    • Route requests to handlers with a macro free API.
    • Declaratively parse requests using extractors.
    • Simple and predictable error handling model.
    • Generate responses with minimal boilerplate.
    • Take full advantage of the tower and tower-http ecosystem of middleware, services, and utilities.

  • If you like this article, you can give me a like on. ­čśÄ Thanks for reading. ­čÖĆ

Other posts


Accounts

Top comments (1)

Collapse
 
burakboduroglu profile image
Burak Boduro─člu

It will continue. (Code Examples)