Use Superscribe.Owin Package in Web API

Introduction

In this article I will use the "Superscribe.Owin" package in the ASP.NET Web API. We use the package for determine what the web framework contributes. Superscribe is a module for the router handler. It is a way to map between the media types and serialiser.

Now for an example.

Step 1

Create an application as in the following:

  • Start Visual Studio 2012.
  • From the Start window Select "New Project".
  • Then select "Installed" -> "Visual C#" -> "Web".

Select Web Application

  • Select "ASP.NET Empty Web Application".

Step 2

Install a package as in the following:

  • Go to the "Tools" menu then select "Library Package Manager" -> "Package Manager Console".
  • Now install the following packages:

    Install-Package Owin
    Install-Package Microsoft.Owin.Host.SystemWeb
    Install-Package Owin.Types
    Install-Package Owin.Extensions

Step 3

Now install the Superscribe.Owin Package through Nuget Manager.

  • Go to the "Tools" menu then select "Library Package Manager" -> "Manage NuGet Package for Solutions".
  • In the search box type "Superscribe".
  • Then select "Superscribe.Owin" and instal it.

Install Superscribe.Owin Package

Step 4

There is a class named "Startup.cs".

Add the following code to it:

  1. using Owin;  
  2. using Superscribe.Owin;  
  3. using System;  
  4. using System.Collections.Generic;  
  5. using System.Linq;  
  6. using System.Web;  
  7.    
  8. namespace SuperOwin  
  9. {  
  10.     public class Startup  
  11.     {  
  12.         public void Configuration(IAppBuilder ibuild)  
  13.         {  
  14.             var Con = new SuperscribeOwinConfig();  
  15.             Con.MediaTypeHandlers.Add(  
  16.             "text/html",  
  17.             new MediaTypeHandler { Write = (rslt, o) => rslt.WriteAsync(o.ToString()) });  
  18.    
  19.             ibuild.UseSuperscribeModules(Con);  
  20.         }  
  21.     }  
  22. }  

Step 5

Add a new class as in the following:

  • In the Solution Explorer.
  • Right-click on the "SuperOwin" project name.
  • Select "Add" -> "Class".

create Class

Add the folowing code:

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using Superscribe.Owin;  
  6. namespace SuperOwin  
  7. {  
  8.     public class Hello: SuperscribeOwinModule  
  9.     {  
  10.        public Hello()  
  11.            {  
  12.              this.Get["/"] = _ => "This is the example of Superscribe Owin:";  
  13.              }  
  14.     }  
  15. }  

Step 6

Now in the Web.config file we ensure that it handles the OWIN request:

  1. <appSettings>  
  2. <add key="owin:HandleAllRequests" value="true" />  
  3. <add key="owin:SetCurrentDirectory" value="true" />  
  4. </appSettings>  

Step 7

Now execute the application:

Output


Similar Articles