Kodice.RapidAPI.Functions.Isolated 1.0.3

Prefix Reserved
There is a newer version of this package available.
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                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Kodice.RapidAPI.Functions.Isolated" Version="1.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Kodice.RapidAPI.Functions.Isolated --version 1.0.3                
#r "nuget: Kodice.RapidAPI.Functions.Isolated, 1.0.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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 Build Status
Production Build Status

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

Offer me a coffee Please consider supporting the development with a little help, just a coffee

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.4 200 1/7/2024
1.1.2 118 1/6/2024
1.1.1 123 1/5/2024
1.0.3 133 1/4/2024