Introduction:
Wikipedia states:
Middleware is computer software that provides services to software applications beyond those available from the operating system. It can be described as "software glue". Middleware makes it easier for software developers to perform communication and input/output, so they can focus on the specific purpose of their application.
Middleware is the software that connects software components or enterprise applications. Middleware is the software layer that lies between the operating system and the applications on each side of a distributed computer network.
Typically, it supports complex, distributed business software applications.
Middleware includes Web servers, application servers, content management systems, and similar tools that support application development and delivery. It is especially integral to information technologies.
Conceptual View:
Typically middleware plays a vital role in the request and response designing. Middleware can modify your request and send it to the server. So in this article we will try to develop sample middleware and check how to Post, Get values.
Requirements:
usingMicrosoft.Owin;
Code Snippet for Sample Middleware
- public class Middleware < TModelType > : OwinMiddlewarewhereTModelType: class, new()
- {
- public Middleware(OwinMiddleware next): base(next)
- {
-
- }
-
- public override Task Invoke(IOwinContext context)
- {
-
- return this.Next.Invoke(context);
-
- }
- }
The following code helps you to connect this middle ware snippet to your class:
- public void Configuration(IAppBuilder builder)
- {
-
- builder.Use < Middleware < RequestHandler >> ();
-
-
-
- builder.Map("/Step1", config =>
- {
-
- config.Use((context, next) => context.Response.WriteAsync("Response Receive from your own middleware "));
-
- });
- }
Middleware passes your request to controller. Let’s take a look to start and test API,
- try
- {
- using(WebApp.Start < StartUpController > ("http://localhost:5888/"))
- {
- Console.WriteLine("Now you can start working on your OWN API");
- Console.ReadLine();
- }
- } catch (Exception ex)
- {
- Console.WriteLine(ex.Message.ToString());
- Console.Read();
- }
Use Postman to Test your API,
Now take a look for post.
Making an API Request to post operation with POSTMAN:
Break Point step IN.
Text Visualization for Request:
Code for Builder to use POST operations,
-
- builder.Use((context, next) =>
- {
- if (context.Request.Method == "POST")
- {
- var form = context.Get < RequestHandler > ("Body");
-
- returncontext.Response.WriteAsync("Post Received :");
- }
- return next();
- });
Download the source code from
OWINSOURCEMIDDLEWARE for c#.net.
References and for more information:
Read more articles on C# Programming: