Kodice.RapidAPI
1.0.1
See the version list below for details.
dotnet add package Kodice.RapidAPI --version 1.0.1
NuGet\Install-Package Kodice.RapidAPI -Version 1.0.1
<PackageReference Include="Kodice.RapidAPI" Version="1.0.1" />
paket add Kodice.RapidAPI --version 1.0.1
#r "nuget: Kodice.RapidAPI, 1.0.1"
// Install Kodice.RapidAPI as a Cake Addin
#addin nuget:?package=Kodice.RapidAPI&version=1.0.1
// Install Kodice.RapidAPI as a Cake Tool
#tool nuget:?package=Kodice.RapidAPI&version=1.0.1
Kodice.RapidAPI
Kodice.RapidAPI has been designed to promote the reuse of common and repetitive code required for authorizing and handling RapidAPI calls to your functions.
About the Project
As an example, if we want to use a new API with .NET Core on a Cloud service of our choice and integrate it with RapidAPI, there are certain steps that we must follow.
- Validate the Secret Key sent via RapidAPI request headers.
- Check if the Customer performing the request has the right to request a specific feature.
Usually these steps are quite tedious, repetitive, and prone to error.
Getting Started
Installing Kodice.RapidAPI
dotnet add package Kodice.RapidAPI
Usage
Minimal API
Minimal APIs are a simplified approach for building fast HTTP APIs with ASP.NET Core. You can build fully functioning REST endpoints with minimal code and configuration.
A simple example on how to add the Kodice.RapidAPI to your API project.
using Kodice.RapidAPI.Minimal;
using Kodice.RapidAPI.Models;
using Kodice.RapidAPI.Constsants;
var builder = WebApplication.CreateBuilder(args);
// Load the configuration from the application settings JSON
var settingsPlans = Subs.FromConfiguration(builder.Configuration);
// RapidAPI authorization can be added both to Groups and single Endpoints
// Create a new group
var client = app.MapGroup("/weather");
client
.AddRapidAPI(settingsPlans)
.MapGet("/forecast", () =>
{ ... })
.WithName("GetWeatherForecast")
.WithOpenApi();
// We can also add to the single Endpoint, and create settings code side.
var customPlans = new Subs("YOUR-RAPID-API-SECRET");
customPlans.Basic.Features.AddRange(new string[] { "feature-01", "feature-02" });
app.MapGet("/temperature", () =>
{ ... })
.AddRapidAPI(customPlans)
.WithName("GetWeatherTemperature")
.WithOpenApi();
Web API
ASP.NET Core supports creating web APIs using controllers or using minimal APIs. Controllers in a web API are classes that derive from ControllerBase. Controllers are activated and disposed on a per request basis.
A simple example on how to add the Kodice.RapidAPI to your API project. The attribute load settings from the application setting file starting from default JSON section "RapidAPI". You can define your own or multiple sections, and pass the string to the attribute.
using Kodice.RapidAPI.Models;
using Kodice.RapidAPI.WebAPI;
using Microsoft.AspNetCore.Mvc;
[ApiController]
[Route("[controller]")]
[RapidAPIAuthorization()]
public class WeatherForecastController : ControllerBase
{
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{ ... }
}
Also possible to add to single Method:
using Kodice.RapidAPI.Models;
using Kodice.RapidAPI.WebAPI;
using Microsoft.AspNetCore.Mvc;
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
[HttpGet(Name = "GetWeatherForecast")]
[RapidAPIAuthorization("MY-CUSTOM-SECTION")]
public IEnumerable<WeatherForecast> Get()
{ ... }
}
Support and Sponsor
Please consider supporting the development with a little help, just a coffee | | Buy me a coffee | |--|--|
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. 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. |
-
net7.0
- Microsoft.AspNetCore.OpenApi (>= 7.0.5)
GitHub repositories
This package is not used by any popular GitHub repositories.