🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

fastapi

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastapi

A simple CLI utility for quickly creating Express-based servers with a single configuration file

0.0.8
latest
Source
npm
Version published
Weekly downloads
493
13.59%
Maintainers
1
Weekly downloads
 
Created
Source

fastapi

Introduction

Fastapi is a simple command-line utility that allows you to create an Express-based server based off of a single configuration file. It's useful for quickly spinning up mock APIs, among other things.

Getting Started

Install the fastapi command-line utility via npm i -g fastapi. Next, create a configuration file like the one we see here.

// config.js
module.exports = {
	// A unique ID for this API
	'id': 'my-api',
	// The port on which Express is to listen
    'port': 7050,
    // Whether or not to log incoming requests to the console (default: true)
    'log': true,
    'routes': {
        '/api/v1/ping': {
            'get': (req, res, next) => {
                return res.send('pong');
            }
        }
    }
};

Next, launch your server as shown below.

$ fastapi -c ./config.js

Defining Multiple APIs

A configuration file can define multiple APIs by exporting an array of configuration objects, like we see here.

module.exports = [
    {
        'id': 'api1',
        'port': 7050,
        'log': true,
        'routes': {
            '/api/v1/ping': {
                'get': (req, res, next) => {
                    return res.send('pong');
                }
            }
        }
    },
    {
        'id': 'api2',
        'port': 7051,
        'log': true,
        'routes': {
            '/api/v1/foo': {
                'get': (req, res, next) => {
                    return res.send('bar');
                }
            }
        }
    }
];
  • Express

Keywords

express

FAQs

Package last updated on 06 Sep 2016

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