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.
-
Update your
.csproj
file to referencePorthor
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 });
}
}
- Transformation of JSON on request/response
- Web UI to register, update and delete resource routes
- Wiki & API documentation