New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@flyweight.cloud/openroute

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@flyweight.cloud/openroute

A lightweight router for Azure Functions with Swagger integration

latest
npmnpm
Version
0.6.3
Version published
Maintainers
1
Created
Source

Flyweight OpenRoute

A lightweight framework for building Swagger/OpenAPI serverless functions for consumption by Microsoft Power Platform and beyond.

Installation

npm i --save @flyweight.cloud/openroute

Usage

The goal is for OpenRoute to require little to no modification of your Azure handlers

import { Context, HttpRequest } from "@azure/functions"
import { get } from "@flyweight.cloud/request";
import Swaggerist, { schemaBuilder, Responses, queryParamBuilder, pathParamBuilder } from "@flyweight.cloud/swaggerist";
import { OpenRoute } from "@flyweight.cloud/openroute"
import { HttpError } from "@flyweight.cloud/openroute/lib/errors";

const API_KEY = process.env.OPENWEATHER_API_KEY;

const exampleWeatherApiResponse = {
  "coord": {
    "lon": -122.08,
    "lat": 37.39
  },
  "weather": [
    {
      "id": 800,
      "main": "Clear",
      "description": "clear sky",
      "icon": "01d"
    }
  ],
  "base": "stations"
};

const swaggerBuilder = Swaggerist.create({
  info: {
    title: "Weather API",
    description: "Flyweights demo weather API",
    version: "1.0.0",
  }
})

const app = new OpenRoute({
  swaggerBuilder,
  cors: {
    allowOrigin: "*",
    allowHeaders: ["*"],
    allowMethods: ["*"],
  }
});

const getCurrentWeatherPathRoute = swaggerBuilder.get("/current/{zipCode}", {
  operationId: "getCurrentWeatherByZip",
  parameters: [...pathParamBuilder({zipCode: "12345"})],
  responses: {
    200: Responses.Success(schemaBuilder(exampleWeatherApiResponse)),
  }
})

app.route(getCurrentWeatherPathRoute, async (context: Context, req: HttpRequest, openRoute: OpenRoute): Promise<void> => {
    context.log("HTTP trigger function processed a request.");

    const zipCode = context.bindingData.zipCode
    let url = `https://api.openweathermap.org/data/2.5/weather?zip=${zipCode}&appid=${API_KEY}`
    const weather = await get(url)

    context.res = {
        body: weather.body,
        headers: openRoute.defaultHeaders(),
    };

});

export default app.getHttpTrigger();

You will also need to modify function.json to add a 'catch-all' route "route": "weather/{*route}"

Check out DemoFunc to see the full featured function and it's settings.

FAQs

Package last updated on 04 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts