[go: up one dir, main page]

0% found this document useful (0 votes)
40 views7 pages

UNIT-3 Backend Frameworks

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 7

UNIT-3

Backend Frameworks

Introduction to Backend Frameworks:

What is a Backend Framework?

A backend framework is a collection of tools, libraries, and standards designed to


help developers to build web applications more quickly and efficiently. They
provide the structure and architecture to manage requests from clients, access
databases, and organize the application’s business logic.

By using a backend framework, developers can focus on developing application


features and functionality, without having to worry about request processing and
other technical details.

Why Backend Frameworks are Important?

- Development Efficiency: Backend frameworks provide a wide array of reusable


features and functions, reducing repetitive work and speeding up the development
process.
- Scalability: With a tried and tested structure, backend frameworks allow
applications to grow and handle high traffic without compromising performance.
- Security: Backend frameworks often come with built-in security features that
help protect applications from attacks such as SQL injection and Cross-Site
Scripting (XSS). (XSS is a client-side vulnerability that targets other application users,
while SQL injection is a server-side vulnerability that targets the application's database.)
- Active Community: Popular backend frameworks have active communities that
can help in troubleshooting and providing support in application development.

Here are some popular backend frameworks:


`
1. Express.js: Express.js is a backend framework based on Node.js that helps
developers build web applications quickly and simply. Express.js is perfect
for small to large web applications, providing great flexibility in designing
application architecture.
Features:
Express. js provides various key features, including routing, middleware(a
web server), templates, error handling, security, and ease of use.
2. Django: Django is a high-level Python web framework that encourages
rapid development and clean, realistic design. It follows the "Don't Repeat
Yourself" (DRY) principle and includes features such as an ORM (Object-
Relational Mapping), authentication, and admin interface.
Features:
• Ease of use: Django is an easy-to-learn and easy-to-use framework,
• Documentation: Django has excellent documentation, which makes it
even easier to learn and use the framework.
• Scalability: The framework is designed to handle high-demand web
applications, which makes it an ideal option for projects that need to be
scalable.( ability to handle workload variation while adding or removing
users with minimal costs.)
• Security: A vast array of built-in security features, such as user
authentication and protection against common attacks such as SQL
injection
• Active community: Django has an active community of developers and
users
3. Ruby on Rails: Ruby on Rails, often simply called Rails, is a web
application framework written in Ruby. It emphasizes convention over
configuration and follows the model-view-controller (MVC) architectural
pattern.
4. Spring Boot: Spring Boot is an open-source Java framework used to create
stand-alone, production-grade Spring-based applications. It simplifies the
development process by providing defaults for configuration and
eliminating boilerplate code.
5. ASP.NET Core: ASP.NET Core is a cross-platform, high-performance
framework for building modern, cloud-based, internet-connected
applications using C#. It is open-source and can run on Windows, macOS,
or Linux.
6. Flask: Flask is a lightweight Python web framework that is simple and easy
to use. It is well-suited for small to medium-sized projects and provides
flexibility in terms of extensions and components.
7. Laravel: Laravel is a PHP web application framework known for its elegant
syntax and expressive features. It provides tools for tasks such as routing,
authentication, caching, and more, making development efficient and
enjoyable.
Features of Laravel:
• Own CLI (Command Line Interface)
• Integrates with MySQL, SQL Server, SQLite, and Postgres.
• Migration of database
• Simple API
• Template Engine

8. FastAPI: FastAPI is a modern, fast (high-performance), web framework for


building APIs with Python 3.7+ based on standard Python type hints. It is
built on top of Starlette for the web parts and Pydantic for the data parts.
9. Koa.js: Koa.js is a lightweight Node.js web framework developed by the
team behind Express.js. It uses modern JavaScript features and is designed
to be more expressive and robust.

Java Spring MVC

Spring – MVC Framework:

Spring MVC Framework follows the Model-View-Controller


architectural design pattern which works around the Front
Controller i.e. the Dispatcher Servlet. The Dispatcher Servlet handles
and dispatches all the incoming HTTP requests to the appropriate
controller. It uses @Controller and @RequestMapping as default request
handlers. The @Controller annotation defines that a particular class is a
controller. @RequestMapping annotation maps web requests to Spring
Controller methods.
The terms model, view, and controller are as follows:
• Model: The Model encapsulates the application data.
• View: View renders the model data and generates HTML output
that the client’s browser can interpret.
• Controller: The Controller processes the user requests and
passes them to the view for rendering.
Dispatcher Servlet
Dispatcher Servlet is the front controller that manages the entire HTTP
request and response handling process. Now, the question is What is
Front Controller? It is quite simple, as the name suggests, when any web
requests are made, the requests will come first to the front Controller
which is nothing but the Dispatcher Servlet. The Front Controller stands
first that is why it’s name is like this. After the requests comes into this,
the dispatcher servlet accepts the requests and decides which controller
will be suitable to handle these requests. Then it dispatches the HTTP
requests to specific controller.
Spring Model-View-Controller Flow Diagram

Spring MVC Framework works as follows:


1. All the incoming requests are intercepted by
the DispatcherServlet that works as the front controller.
2. The DispatcherServlet then gets an entry of handler mapping from
the XML file and forwards the request to the controller.
3. The object of ModelAndView is returned by the controller.
4. The DispatcherServlet checks the entry of the view resolver in the
XML file and invokes the appropriate view component.
Advantages of Spring MVC Framework
• The container is used for the development and deployment of
applications and uses a lightweight servlet.
• It enables rapid and parallel development.
• Development of the application becomes fast.
• Easy for multiple developers to work together.
• Easier to Update the application.
• It is Easier to Debug because we have multiple levels in the
application.
Disadvantages of Spring MVC Framework
• It has high complexity to develop the applications using this
pattern.
• It is not suitable for small applications which affect the
application’s performance and design.

Spring Framework and its Features

The Spring Framework is one of the most popular open-source frameworks for
building enterprise-level Java applications. It provides comprehensive
infrastructure support for developing Java applications. Below are some of its key
features:
1. Inversion of Control (IoC): The core principle behind Spring is Inversion
of Control, also known as dependency injection. In IoC, the control of object
creation and lifecycle is shifted from the application code to the Spring
container, which manages the objects and their dependencies.
2. Aspect-Oriented Programming (AOP): Spring provides support for AOP,
allowing developers to modularize cross-cutting concerns such as logging,
security, and transaction management. AOP enables the separation of
concerns, making it easier to maintain and manage code.
3. Modular: Spring is designed in a modular fashion, with a set of distinct
modules for various functionalities such as data access, web development,
messaging, etc. Developers can use the modules as needed, which promotes
flexibility and scalability.
4. Transaction Management: Spring offers a powerful abstraction for
transaction management, supporting both programmatic and declarative
transaction management. It integrates with various transaction
management APIs, including JDBC, JTA, and Hibernate, to provide
consistent transaction support across different environments.
5. Spring MVC: Spring MVC is a web framework built on top of the Spring
Framework, providing a model-view-controller architecture for building web
applications. It offers features such as robust request handling, flexible
configuration, and support for various view technologies like JSP,
Thymeleaf, and FreeMarker.
6. Dependency Injection (DI): Spring facilitates loose coupling between
components through dependency injection. It manages the dependencies of
objects and wires them together at runtime, which improves testability,
maintainability, and reusability of code.
7. Spring Boot: Spring Boot is a project within the Spring ecosystem that
simplifies the configuration and deployment of Spring-based applications.
It provides auto-configuration, embedded application servers, and
production-ready features out of the box, enabling developers to quickly
bootstrap Spring applications with minimal setup.
8. Integration with Other Frameworks: Spring integrates seamlessly with
other popular frameworks and technologies such as Hibernate, JPA, JMS,
RESTful services, and more. This interoperability allows developers to
leverage the strengths of different technologies while benefiting from the
Spring ecosystem's features.
9. Testing Support: Spring provides support for unit testing and integration
testing through the Spring TestContext Framework. It offers features like
dependency injection for test instances, transaction management, and
support for various testing frameworks such as JUnit and TestNG.
10. Security: Spring Security is a powerful and customizable security
framework that provides authentication, authorization, and protection
against common security vulnerabilities. It integrates seamlessly with
Spring applications, offering comprehensive security features for protecting
web and API endpoints.
These are just some of the key features of the Spring Framework. Its extensive
ecosystem and active community make it a popular choice for developing robust
and scalable Java applications.
Spring Container / Inversion of Control (IoC) Container:

The IoC container is responsible to instantiate, configure and assemble the


objects. The Inversion of Control (IoC) container gets informations from the XML file
and works accordingly. The main tasks performed by IoC container are:
o to instantiate the application class
o to configure the object
o to assemble the dependencies between the objects
POJO Classes:
• Modeling Business Logic: POJO classes in a Spring application typically
represent domain objects or business entities. These classes contain
properties and methods that model the behavior and state of the
application's business domain.
• No Dependency on Frameworks: POJO classes are pure Java objects
that do not depend on any specific framework or technology. They are
simple and easy to understand, making them ideal candidates for use in
Spring applications.
• Encapsulation of Data and Behavior: POJO classes encapsulate both
data (in the form of properties) and behavior (in the form of methods),
adhering to object-oriented principles. They provide a clean and modular
way to organize the application's logic.
Java Bean Class:
• Managed by Spring Container: Java Bean classes, when managed by the
Spring container, are referred to as Spring beans. These are POJO classes
configured within the Spring container for instantiation, dependency
injection, and lifecycle management.
• Configuration Metadata: Java Bean classes are typically annotated or
configured using XML to provide metadata to the Spring container. This
metadata includes information such as bean scope, dependencies,
initialization parameters, and lifecycle settings.
XML Configuration File:
XML configuration files are commonly used to provide metadata for configuring
beans within the Spring container. Here's how you can define configuration
metadata using an XML file:
1. Create XML Configuration File: Start by creating an XML file, commonly
named applicationContext.xml or any other meaningful name, to hold the
Spring configuration metadata.
2. Define the Spring Container: Begin the XML file by defining the Spring
container. This is typically done using the <beans> element.
<?xml version="1.0" encoding="UTF-8"?>
<beans

<!-- Bean definitions go here -->

</beans>
Bean Objects:
In the Spring Framework, bean objects are instances of classes that are managed by the
Spring IoC (Inversion of Control) container. These bean objects are configured and
maintained by the container, allowing for centralized management of application
components.

You might also like