Kodice.RapidAPI.Functions.Isolated
1.0.3
Prefix Reserved
See the version list below for details.
dotnet add package Kodice.RapidAPI.Functions.Isolated --version 1.0.3
NuGet\Install-Package Kodice.RapidAPI.Functions.Isolated -Version 1.0.3
<PackageReference Include="Kodice.RapidAPI.Functions.Isolated" Version="1.0.3" />
paket add Kodice.RapidAPI.Functions.Isolated --version 1.0.3
#r "nuget: Kodice.RapidAPI.Functions.Isolated, 1.0.3"
// Install Kodice.RapidAPI.Functions.Isolated as a Cake Addin #addin nuget:?package=Kodice.RapidAPI.Functions.Isolated&version=1.0.3 // Install Kodice.RapidAPI.Functions.Isolated as a Cake Tool #tool nuget:?package=Kodice.RapidAPI.Functions.Isolated&version=1.0.3
Kodice.RapidAPI.Functions.Isolated
Kodice.RapidAPI.Functions.Isolated has been designed to promote the reuse of common and repetitive code required for authorizing and handling Rapid (former RapidAPI) calls to your functions.
About the Project
As an example, if we want to use a new API with Azure Function Isolated .NET 8 on Azure and integrate it with Rapid (former RapidAPI), there are certain steps that we must follow. Usually these steps are quite tedious, repetitive, and prone to error.
- Validate the Secret Key sent via RapidAPI request headers.
- Check if the Customer performing the request has the right to request a specific feature.
Getting Started
Installing Kodice.RapidAPI.Functions.Isolated
dotnet add package Kodice.RapidAPI.Functions.Isolated
Project status
Environment | Status |
---|---|
Development | |
Production |
Usage
Azure Functions V4
A .NET project for Azure Functions using the isolated worker model is basically a .NET console app project that targets a supported .NET runtime.
A simple example on how to add the Kodice.RapidAPI to your API project.
[Function(nameof(Create))]
public HttpResponseData Create([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "v1/create")] HttpRequestData req)
{
// Create your subscription / feature mapping
SubscriptionCollection roles = new SubscriptionCollection();
roles.Add(SubscriptionTypes.BASIC, new Feature("TEST-A"));
roles.Add(SubscriptionTypes.BASIC, new Feature("TEST-B"));
roles.Add(SubscriptionTypes.PRO, new Feature("TEST-C"));
// Set your Secret, User, etc.
RapidHeadersValues values = new RapidHeadersValues()
{
ProxySecret = "MYSECRET"
};
var rapid = req.GetHeaders(roles);
// Check if proxy secret matches
// You can also check for other parameters - Subscriptions later on
// You should not proceed beyond this point in a real scenario
var hasSecurity = rapid.IsSecure((headers, values) =>
{
return (headers.ProxySecret == values.ProxySecret);
},
values);
// Checking simply for Subscription, for Feature in Subscription, or for Subscription and Feature
// These will succeed
var hasSub = rapid.HasSubscription(SubscriptionTypes.BASIC);
var hasFtAllA = rapid.HasFeature("TEST-A");
var hasFtAllB = rapid.HasFeature("TEST-B");
var hasFtAllC = rapid.HasFeature("TEST-C");
var hasFtProC = rapid.HasFeature(SubscriptionTypes.PRO, "TEST-C");
// These will fail
var hasFtProA = rapid.HasFeature(SubscriptionTypes.PRO, "TEST-A");
var hasFtAllX = rapid.HasFeature("TEST");
// If everything is OK keep going
var response = req.CreateResponse();
response.WriteString("Well done!");
}
Support and Sponsor
Please consider supporting the development with a little help, just a coffee
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- Microsoft.Azure.Functions.Worker.Core (>= 1.16.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.