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

@antklim/api-to-cloud

v0.2.0

Published

This tool injects cloud specific integration points to API definition in Swagger.

Downloads

8

Readme

API to Cloud

Build Status Codacy Badge Codacy Badge

This tool injects cloud specific integration points to API definition in Swagger.

Installing

This is a NodeJS module available through the npm register.

Installation is done using the npm install command:

$ npm install @antklim/api-to-cloud

Usage

After installation api-to-cloud CLI will be available in node_modules/.bin.

Usage: api-to-cloud [options]


  Options:

    -V, --version             output the version number
    -a, --api <path>          API definition file path
    -i, --integration <path>  API integration file path
    -o, --output <path>       path to output extended API file
    -c, --cloud [cloud]       cloud provider [AWS], default 'AWS'
    -f, --format [format]     output file format [yaml|yml|json], default 'yaml'
    -h, --help                output usage information

Run the following command to produce swagger file with AWS specific integration points:

$ node_modules/.bin/api-to-cloud --api test-api.yaml \
                                 --integration test-integration.yaml \
                                 --output aws.yaml

Programmatic API

parser

The parser module provides utilities for parsing of API and integration point descriptions. Currently supported two formats: YAML and JSON. It can be accessed using:

const {parser} = require('@antklim/api-to-cloud')

parser.parse(file)

  • file String - path to the file to parse
  • Returns: Promise - resolves with the file data parsed into object

Example:

parser.parse('input.yaml')
  .then(data => console.log(JSON.stringify(data, null, 2)))
  .catch(err => console.error(err))

parser.for(format)

  • format String - file format to parse
  • Returns: Function - parser function or null

encoder

The encoder module provides utilities for formatting and storing of API definition. Currently supported two formats: YAML and JSON. It can be accessed using:

const {encoder} = require('@antklim/api-to-cloud')

encoder.save(data, file, format)

  • data Object - data to write to file
  • file String - path to file to write
  • format String - format to save payload in
  • Returns: Promise - resolves when payload written into the file

Example:

encoder.save({'foo': 'bar'}, 'example.yaml', 'yaml')
  .then(() => console.log('Payload written into \'example.yaml\''))
  .catch(err => console.error(err))

encoder.for(format)

  • format String - file format to encode to
  • Returns: Function - encoder function or null

integrator

The integrator module provides utilities for merging pure API description in Swagger format with cloud specific integration points. It can be accessed using:

const {integrator} = require('@antklim/api-to-cloud')

integrator.extend(api, integrationPaths, cloud)

  • api Object - Swagger API definition
  • integrationPaths Object - cloud integration points to add to API
  • cloud String - target cloud provider, [AWS]
  • Returns: Object - extended Swagger API (API + integrations)

Format of the integration points object:

path:
  method:
    integrationPoint: ...

Example of integration object:

/pets:
  get:
    x-amazon-apigateway-integration:
      responses:
        default:
          statusCode: "200"
      requestTemplates:
        application/json: "{\"statusCode\": 200}"
      passthroughBehavior: "when_no_match"
      type: "mock"
  post:
    x-amazon-apigateway-integration:
      responses:
        default:
          statusCode: "200"
      requestTemplates:
        application/json: "{\"statusCode\": 200}"
      passthroughBehavior: "when_no_match"
      type: "mock"
/pets/{petId}:
  get:
    x-amazon-apigateway-integration:
      responses:
        default:
          statusCode: "200"
      requestTemplates:
        application/json: "{\"statusCode\": 200}"
      passthroughBehavior: "when_no_match"
      type: "mock"

integrator.cleanApi(api, removables)

  • api Object - Swagger API definition
  • removables Array - the list of paths to remove from the API description
  • Returns: Object - API definition cleaned from removables

Built With

  • js-yaml - YAML parser/encoder for JavaScript
  • ava - Futuristic test runner
  • ESLint - JavaScript linting utility
  • testdouble - JavaScript test mocking library

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details