ReqHub 1.2.0
See the version list below for details.
dotnet add package ReqHub --version 1.2.0
NuGet\Install-Package ReqHub -Version 1.2.0
<PackageReference Include="ReqHub" Version="1.2.0" />
paket add ReqHub --version 1.2.0
#r "nuget: ReqHub, 1.2.0"
// Install ReqHub as a Cake Addin #addin nuget:?package=ReqHub&version=1.2.0 // Install ReqHub as a Cake Tool #tool nuget:?package=ReqHub&version=1.2.0
ReqHubNuGet
ReqHub middleware for C# projects. Distribute your API using the ReqHub platform in just a few lines! For more information, visit https://reqhub.io.
Distributing an API
To distribute an API for clients to consume with API keys, add these two lines to your Startup.cs
:
/// Startup.cs
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// Visit https://reqhub.io to get your API keys
services.AddReqHub("yourPublicKey", "yourPrivateKey");
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// ...
// app.UseRouting();
// Put this after app.UseRouting() and before app.UseEndpoints().
// It verifies requests against the platform and either
// continues execution or returns a 403 forbidden response
// if the request is invalid (bad API key, contents tampered with, etc.)
app.UseReqHub();
// app.UseEndpoints(...);
// ...
}
}
That's it! 🎉
Identity
You may want to be able to uniquely identify a client. Inside your controller methods you can access the clientId with:
this.User.GetClientId();
How it works
Clients consuming your API create a request hash using their own API keys, which the middleware forwards to the platform along with your request hash. If everything matches up on the platform, the request is allowed to continue.
Consuming an API
To consume an API, configure a client and inject it into your controllers/services.
/// Startup.cs
public class Startup
{
// ...
public void ConfigureServices(IServiceCollection services)
{
// Visit https://reqhub.io to get your API keys
services.AddApiClient("https://api-base-address/", "yourPublicKey", "yourPrivateKey", "serviceName");
// Add as many as you like!
services.AddApiClient("https://api2-base-address/", "anotherPublicKey", "anotherPrivateKey", "serviceName2");
}
}
(it looks like a lot of code, but we promise it isn't 👌):
/// ExampleController.cs
public class ExampleController : ControllerBase
{
private readonly IApiClient exampleApiClient;
// Resolve the API client using dependency injection
public ExampleController(ApiClientResolver apiClientResolver)
{
this.exampleApiClient = apiClientResolver("serviceName");
}
[HttpGet]
public async Task<IEnumerable<Example>> Get()
{
return await this.exampleApiClient.GetAsync<IEnumerable<Example>>("example/endpoint");
}
}
Contributing
Go for it! If we're missing something or you're running into a problem, either let us know in an issue or send us a pull request. We think we're pretty reasonable 😘
License
MIT, babe -- go nuts! 🎉
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.AspNet.WebApi.Client (>= 5.2.7)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.Extensions.DependencyInjection (>= 3.1.0)
- Microsoft.Extensions.Http (>= 3.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.