Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

NicatorBa/Porthor

Repository files navigation

Porthor

NuGet GitHub issues GitHub license

What's Porthor?

Porthor is an API gateway middleware for ASP.NET Core 2.0. It offers an easy to use way to register APIs from other sources to your application. You can also protect your API by using ASP.NET Core policy-based authorization.

Getting started

  • Update your .csproj file to reference Porthor package

  • Configure Porthor service in Startup:

public class Startup
{
    public void ConfigureServices(IServiceCollection service)
    {
        // Register the Porthor services
        // with your gateway configuration
        services.AddPorthor()
            // Enable checking if user is authenticated by default
            // Can be overridden for certain resources with their property `AllowAnonymous`
            .AddAuthenticationValidation()

            // Protect your API with policiy-based authorization
            .AddAuthorizationValidation()

            // Activate query string checking
            // Offers a more strict way to handle query params for resources
            .AddQueryStringValidation()

            .AddContentValidation(options =>
            {
                // Enable content body validation for POST and PUT methods
                options.Enabled = true;
                // Register content validator for specific media type
                options.Add<JsonValidator>(MediaType.Application.Json);
                options.Add<XmlValidator>(MediaType.Application.Xml);
            });
        });
    }

    public void Configure(IApplicationBuilder app)
    {
        // Minimal configured resource
        // HttpMethod: supported Http request method
        // FrontendPath: your application api endpoint
        // BackendUrl: endpoint where the request is to be redirected
        var routingRule = new RoutingRule {
            HttpMethod = HttpMethod.Get,
            FrontendPath = "api/samples",
            BackendUrl = "http://example.org/api/v1/samples"
        }

        // Use Porthor with predefined resource
        app.UsePorthor(new[] { routingRule });
    }
}

Roadmap

  • Transformation of JSON on request/response
  • Web UI to register, update and delete resource routes
  • Wiki & API documentation