npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kodice.one/rapid-api-azure

v1.2.5

Published

RapidAPI for Azure Functions library to bind your APIs

Downloads

2

Readme

RapidAPI library for Azure Functions 🔗

RapidAPI for Azure Functions Javascript has been developed having in mind reusability of the usual tedious code that is needed to authorize and manage RapidAPI calls to your functions.

But, less talk and let see some code.

For example, when we implement a new Azure Function to be used with RapidAPI, we need to go thorugh some steps:

  • 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.

Enough, let see some code:

//  Let's define some features for the RapidAPI plans, which are: BASIC, PRO, MEGA, ULTRA.
//  Features keys are defined at your discretion.
//  As rule of thumb more features are available as higher the Plan is.
const Plannings = new PlanMapper();
Plannings.Features = [
    new Feature(RapidPlans.BASIC, ['feat-easy']),
    new Feature(RapidPlans.PRO, ['feat-easy', 'feat-medium']),
    new Feature(RapidPlans.MEGA, ['feat-easy', 'feat-medium', 'feat-hard']),
    new Feature(RapidPlans.ULTRA, ['feat-easy', 'feat-medium', 'feat-hard', 'feat-impossible'])
];

//  Azure Function itself index.ts
import { rapidApiHeaders, RapidHeaders, RapidHeadersError } from "rapid-api-azure";

const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise<void> {

  //    Load your RapidAPI Secret Key
  const rapidSecret: string = process.env["RapidApiSecret"];

  //    Map headers and Check the SecretKey with 'rapidApiHeaders' 
  //    If the header does not match the RapidAPI secret
  //        a new RapidHeadersError exception is thrown
  const rapidHeaders: RapidHeaders = rapidApiHeaders(req, rapidSecret);

  //    Check plans and features
  const hasFeature: boolean = Plannings.hasFeature(rapidHeaders.Subscription, "feat-medium");

  //    What to do if you Customer doesn't have Plan-to-Feat?
  if (!hasFeature) {
      console.log.error('Oh no!');
  }
};

Install

Simply run:

npm install rapid-api-azure

Motivation

Biggest benefit of RapidAPI is to have a facing platform for your API, that allows you to create plans and mappings. This library has been developed having in mind reusability of the usual tedious code that is needed to authorize and manage RapidAPI calls to your Azure Functions Javascript. For example, when we implement a new Azure Function to be used with RapidAPI, we need to go thorugh some steps:

  • 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.

Library

Functions

rapidApiHeaders (request: HttpRequest, secret: string): RapidHeaders

Converts Azure Function http request headers in a typed object. Plan is defined within as enumerator. The function will as well check if SecretKey provided matches the Key in your settings.

Classes

PlanMapper

Defines features for the RapidAPI plans, which are: BASIC, PRO, MEGA, ULTRA. Features keys are defined at your discretion. As rule of thumb more features are available as higher the Plan is.

Feature

Plan to Feature map to be used to check if Plan has a specific feature with PlanMapper

PlanMapper.hasFeature (plan: RapidPlans, feature: string): boolean

Check if the Plan sent by RapidAPI match with the features defined in the PlanMapper.Features property.

Errors

RapidHeadersError

Custom error that is raised when the SecretKey does not match with the one provided by the RapidAPI header.

Models

RapidPlans enumerator

NONE,BASIC, PRO, ULTRA, MEGA, CUSTOM

RapidPlansNames constants

None, Basic, Pro, Ultra, Mega, Custom

About

This project is maintained by KODICE.

License

rapid-api-azure is available under the MIT license.

RapidAPI is name registered by RapidAPI

Copyright (c) KODICE

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.