ASP.NET Core Web API Tutorial – Part 1

By | September 14, 2017

Before ASP.NET Web API core, the two-different framework MVC and Web API were pretty much similar. Both used to support Controller and action methods. In earlier version, the main purpose of Web API was to make REST API calls and there were view engine like Razor. On the other hand, MVC was designed for HTML front ends to communicate to backend in a standard a web application. However, when ASP.NET Web API core was released, the main target was to support JSON based REST API. It combines the key feature of both MVC and old Web API framework.

ASP.NET Core Web API Architecture

ASP.NET Web API is mainly based on the MVC architecture. In below figure, it shows that current .NET framework supports both ASP.NET 4.6 and Core 1.0, recently Core 2.0 has been released. Core framework can be deployed in different OS platform. And the underline compilers and run time library accessible by different OS deployment. The .NET framework and .NET Core also share a number of APIs..NET Framework and .NET Core

ASP.NET 4.6 and ASP.NET Core 1.0

FIGURE 1: ASP .NET WEB API CORE. THIS IMAGE HAS BEEN TAKEN FROM ASP.NET

 

ASP.NET Core Component

FIGURE 2:MAIN COMPONENT OF ASP.NET

Fig [2] shows that the main component of ASP.NET Core is the MVC 6 which has included Web API and WEB View. Another important component is the SignalR, this is a library that simplifies the process of detecting real time changes on a web application and perform action based on the changes. As soon as the data in server is updated client would get the updated data.

SignalR provides a simple API to make server-to-client remote procedure calls (RPC) that invoke JavaScript functions in client browsers once the data in server is changed from server. SignalR also provides API for connection management and grouping connections.

SignalR

Figure 3: How SignalR Works? Image taken from https://docs.microsoft.com/en-us/aspnet/signalr/overview/getting-started/introduction-to-signalr

The next important component for ASP.NET is the EF Core. Entity Framework Core is a lightweight, extensible, and cross-platform solution for entity framework data access technology. This has been released with ASP .NET Core in order to support its cross platform deployment. This is also an object-relational mapper (O/RM) that config the mapping between database object and .NET object model. Therefore, developer does not need to code for the data-access layer.

New Features available in ASP.NET Core Web API

Cross Platform

ASP.NET Web API Core is cross-platform; therefore, it is suitable for running on any platform like Windows, Mac, or Linux. Earlier ASP.NET applications were not able to run on Linux and Mac operating system.

Backward Complatibility

For existing application, ASP.NET Web API Core supports two framework.

Faster

ASP.NET Web API Core is much faster than previous versions.

Static Content

wwwroot folder contain all the static content e.g. js, css, images.Static Content

ASP.NET Core with Angular 2
Build a Real-world App with ASP.NET Core and Angular 2 (4+)

  • Build a full-stack web app with ASP.NET Core, Entity Framework Core and Angular 2 & 4.
  • Implement a Clean & Decouple Architecture.
  • Properly implement the Repository and Unit of work patterns.
  • Troubleshoot common runtime errors.
  • Test APIs using PostMan.
  • Integrate ASP.NET MVC/Core with AngularJS.
  • Understand and apply the Dependency Inversion Principle (DIP).
  • Use the new dependency injection feature in ASP.NET Core.
  • Build APIs with ASP.NET Core
  • and more….

Razor Pages

There is the new view engine,  Razor Pages (new in 2.0) is a  page-based programming model. As most of the web sites are usually a collection of multiple web pages., this engine is very helpful for developing web applications faster and more efficiently .

Recently ASP .NET Core 2.0 has been released with some more feature,. In a summery we can say the following are the key feature for ASP .NET Core Web API

  • A modern framework for developing web UI and web APIs in the same application.
  • Modern client-side frameworks and development workflows has been integrated.
  • Configuring a complete integration and cloud based deployment is very easy and flexible.
  • It provides Built-in dependency injection.
  • This is a lightweight, high-performance, and modular HTTP request pipeline.
  • Its help to host on IIS or to self-host inside the application process.
  • It is possible to run on .NET Core along with traditional ASP .NET.
  • Tooling has been simplified to a great extent for being efficient enough for modern web development. Adding a MongoDB Drive is just few click action to be done.
  • Cross platform support.

Step forward in 2017: Build in-demand career skills with Coursera

Comprehensive Step by Step Example using Fiddler Tool to Consume a RESTful Service

Fiddler is a very popular debugging as well as performance evaluation tool for REST API call among developers. Fiddler is a powerful debugging proxy to Test REST API call as loges everything between local server and internet and inspects the traffic and every incoming and outgoing data. As this is a debugging proxy, it allows to set breakpoint to identify potential issue, scalability and eventually helps to evaluate the performance for the application.

Fiddler Key Features:

  • Fiddler can be used to debug web traffic from any platform, e.g. Windows-based PC, Mac or Linux system, mobile devices on both ios and android.
  • Fiddler can capture traffic from remote computers and network devices that support proxy servers.
  • Fiddler supports any client which is pretty much any browser.
  • Fiddler can decrypt HTTP traffic.
    Fiddler as Decrypt HTTP Traffic Tool
  • Fiddler helps to analyze the response and request data with so much flexibility using a very rich tools.Analyze Request and Response Data
  • One of the major purpose that developer uses fiddler tool is to evaluate the performance of the application. Fiddler timeline view give extensive information for the performance evaluation.
  • Fiddler can even filter out interested traffic.Filter out Interested Traffic
  • It is even possible to set the GEO location in order to analyze the traffic for a particular geo location.GEO Location
  • The list of filter option is very rich.Rich Filter Options

Step by Step Live Example:

  • Download fiddler from here.
  • Install fiddler to the PC.
  • Open Fiddler.
  • Right click the process from the left side explorer and Select Filter Now> Show only Process <processId>.1. Process
    This will only show the process that we are interested of.
    In order to use a third party application , for this example we would use the api from https://randomuser.me/
  • Compose API
    • Click on the ‘Compose Tab’
    • Type ‘https://randomuser.me/api/?results=50’ URL
    • Set method as GET
    • Add ‘Content: application/json’
    • Hit Excecute2. Execute
  • Inspect Response
      • The response would be

    3. Inspect Response

      •  Click on the ‘Inspector Tab’
      • Click ‘Headers’

    4. Headers

      • Click on the Syntax View

    5. Syntax View

      • Select JSON

    6. JSON View

There are many other uses of fillder application for checking caching, authentication, network performace and so on.
Career skills to jumpstart your future.
You can follow below for more helpful material regarding related technologies here: