Posts

ASP.NET Core 9: Localized Response from ASP.NET Core 9 API

Image
When building enterprise applications, it is highly important to support different language and localized settings. Recently, while discussing with one of my student, a point raised on the multi-lingual response management from the API applications. The need was to send the response from the API based on the local language settings sent to it in the HTTP request. One of the benefits of the ASP.NET Core is an easy support for Localization using the Middleware. The UseRequestLocalization() Middleware is used to configure the Localization options so that the API can be configured to use the Localized resource before sending the response. The RequestLocalizationOptions  class is used to set the configuration for default culture that can be changed while processing the request based on the Accept-Language header received from the HTTP Request. How the Localization is handled in ASP.NET Core Figure 1, explains the localized response processing Figure 1: The Localized Response Processing ...

Angular: Creating Dynamically Updating Chart with ng2-charts and chart.js with capacilities of Rxjs

I wrote an article on creating Real-Time Charts using SignalR and Blazor . After reading this article, some of my students were looking for the same chart in Angular, so I decided to write on this topic. In Angular, we can use JavaScript timer functions, e.g., setInterval(), to call the server side to fetch data and process it on the client side. But instead of using such a JavaScript function, we should use  RxJs  to handle time-based or time-bound operations. What is RxJs?   RxJS, or Reactive Extensions for JavaScript, is a library for composing asynchronous and event-based programs using observable sequences. RxJs provides a powerful and flexible way to handle data streams and asynchronous events that makes it easier and smarter to manage complex asynchronous tasks in JavaScript applications.      Following are some of the most important key features of RxJs: Observables: They represent data streams. These data steams can be observed and manipulate...

Python: Creating REST APIs using Flask and SQLAlchemy

Image
In the previous article , I covered database access from the Python application using the SQLAlchemy package. In this article, we will implement the REST APIs in Python using the Flask framework.  What is Flask? Flask is a popular microweb framework that is written in Python. It is designed to be lightweight and modular, which makes it easy to create web applications quickly. It provides all those essentials needed to build a web app, such as routing, request handling, and templates while allowing developers the freedom to choose additional libraries and tools based on their needs. Following are some of the important Flask objects: The request Object The request object in Flask is used to handle incoming request data. This contains all the data sent by the client in an HTTP request including form data, query parameters, headers, cookies, etc. Following are some common attributes and methods of the request object: request.method : The HTTP method used for the request (e.g., GET, P...

Python: Using SQLAlchemy to perform database operations

Image
In this article, we will see a simple approach for performing database operations using SqlAlchemy in Python programming language. Python is a versatile and very powerful programming language that is widely used in various fields such as web development, data analysis, artificial intelligence, scientific computing, automation, etc. While working on any of the fields in Python, we need to access the database and perform operations on it. It is highly recommended that the database operations should be performed using a very powerful database access object model. This is where SQLAlchemy comes into the picture. SQLAlchemy is a powerful SQL toolkit and Object-Relational Mapping (ORM) library for Python. It provides a flexible and efficient way to interact with relational databases using Python objects.  I t provides a full suite of enterprise-level persistence patterns, designed for efficient and high-performing database access   To understand and implement the code for this arti...

Blazor: Implementing the Role Based Routing in Blazor WebAssembly

Image
In this article we will implement the Role-Based routing in Blazor WebAssembly application. In previous article , I have explained the Token Based Authentication and Policy-Based Authorization. In that article, I have explained the mechanism of using the UserName and RoleName in the JSON Web Token (JWT) claims. In the current article, we will use the same API project (I have provided the link at the end of this article.) for security and the Blazor WebAssembly project will invoke the API endpoints securely. Figure 1 shows the implementation guideline. Figure 1: The Implementation As shown in Figure 1, the execution takes place as follows: The Blazor WebAssembly client application make call to API application by sending the credentials. The API application generate JSON Web Token based on UserName and RoleName. The Token along with the UserName and RoleName is send to the client. The Blazor Application saves the Token UserName, and RoleName to Session Storage. Blazor WebAssembly cli...