Posts

ASP.NET Core 8: Sending PDF Files from ASP.NET Core API to Angular Client and Open the PDF File in Angular Application

Image
In this article, we will implement the mechanism of sending the PDF file from ASP.NET Core API to Angular client application. The Angular client application will download will open this PDF file directly in the browser. It is always important to show the data stored in PDF document from server application to the client application without explicitly downloading it on the client (User may take a call to further save it). In ASP.NET Core we can make use of the Results  class and its File() method to send file from API in the HTTP GET response. This file response can be received by the Angular Client application in the BLOB response type. In the Angular application, we can use the createObjectURL() method of the window.URL interface object to create string URL so that the file can be directly opened in the browser. The Figure 1 shows the implementation type. Figure 1: The Implementation In ASP.NET Core, we cand use the File() method of the Result class to write the Stream into the HTTP Re

Power BI: Accessing Data From Azure Hosted ASP.NET Core API to create Chart

Image
In the modern days of the application development the Power BI has been used a lot to turn related and unrelated data into the coherent, visually immersive and interactive insights. The data can be received from Excel Spreadsheets, SQL Server Database, cloud-based applications, etc. As shown in Figure 1, the Power BI can access data from various sources. Figure 1: The Get Data Features As shown in Figure 1, Power BI Uses various sources for accessing data so that it can be used by the business decision makers to get data for data transformation and use it in Visualize form to create charts Important Note: To Create database in Azure SQL and Publish API to cloud, you must have the Azure Subscription . Currently, most the data-oriented applications use REST APIs for data communications and Data fetching. Naturally, if we are using the Power BI for Data Visualization and Data Intelligence then what if the Data is to be received from the REST API then how we can access it in Power BI? In t

ASP.NET Core 8 API: Opening Excel File On The Server and Return its contents in JSON format

Image
ASP.NET Core is the best technology for building WEB Apps and API Services. The ASP.NET Core API offers features for building Data Communication services. We can connect various data providers to read their data and return it to the client applications. One such capability is to open an Excel file on the server and read its contents so that the client can respond to them in JSON format. Excel files play a very important role in storing data so that this data can be used for various business intelligence processes. We can develop ASP.NET Core API to directly open the Excel file on the server and return its contents to the client without downloading the file on the client. Figure 1 shows the application development process. Figure 1: Reading Excel file using ASP.NET Core API app The advantage of the above approach is that the file is available on the server and its data is sent to the client. To implement the solution we will be using the ExcelDataReader.DataSet package. This package is

ASP.NET Core: Using HTTPCLIENT with a Correct Way

Image
If you are building .NET Applications, then certainly your application needs to perform external API calls using HTTP Protocol.  Perhaps, if I say that the HTTP calls is a data fetching backbone of your applications then I won't be wrong. In such scenarios to perform HTTP calls we have the HttpClient class in .NET. The HttpClient class offers a great abstraction over managing HTTP Communications especially when the data communication is in the form of the JSON. The Figure 1 explains the scenario of the HTTP API calls. Figure 1: The HttpClient to Access HTTP APIs   But here are some possibilities where the HttpClient may be misused: If the new HttpClient instance is created every time, then that may result into port exhaustion.  Since the HttpClient implements IDisposable interface, we can use the HttpClient in the using statement for disposing its instance, but the problem is even after the HttpClient instance is disposed the underlying socker is not immediately release and this si

ASP.NET Core 8 API: How to implement REPR Pattern Endpoints in ASP.NET Core 8 API

Image
ASP.NET Core, is one of the best technologies for building APIs. In the modern world customer focused applications, the design and implementation of APIs is mandatory for fast data communications. The data can be in JSON format or even may be in the form of Binary Stream. In ASP.NET Core 6 onwards we have been introduced with Minimal APIs. The Minimal API eliminates the need for creating controllers. Yes, use of the controller approach is based on the typical MVC design approach. The MVC Controllers involves Views, ViewModels, etc. But in APIs, we use DTOs. Hence, the controller's approach does not really have any advantages because it has tendency to become bloated with numerous dependencies as we increase the number of endpoints, this also make the maintenance as a challenge. The Minimal APIs are the best. The Minimal API approach offers an endpoint that is directly mapped with the HTTP request type, and it provides a highly cohesive approach of dependency management along with r