• Stars
    star
    1,193
  • Rank 39,220 (Top 0.8 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 8 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

IBM API Connect Microgateway framework, built on Node.js & Nginx

Introduction

This is fork with datastore cache for http-responses. To enable it you must set env var DATASTORE_USE_LOCAL_CACHE=true.

The Microgateway is an developer-focused, extensible gateway framework written in Node.js for enforcing access to Microservices & APIs - https://developer.ibm.com/apiconnect/. It supports the following core features:

  • Secure and control access to APIs using Swagger (OpenAPI) Specification
  • Collection of pre-built gateway policies for API Key validation, OAuth 2.0, rate limiting, and JavaScript
  • Create gateway policies (security, routing, integration, etc... ) using Swagger extensions (API Assembly)
  • Simple interfaces for creating your own gateway policies.

The role of a Gateway in an API architecture is to protect, enrich and control access to API services. These sets of capabilities are often related to security and rate limiting, but it also includes the ability to do deeper message inspection. For example, you may want to insure that the message received is properly formed JSON, XML, or data following your own specific format. In addition, the Gateway can modify the payload or transform it to meet old or new interfaces for the API backend. Finally, the Gateway can invoke multiple services and aggregate responses from multiple API backends.

The Microgateway is the foundation for all of those things. It is optimized to perform security, rate limiting, and much more complex packet processing through a highly flexible flow-engine.

The flow-engine is a processing unit that allows you to define a sequence of processing policies or tasks that get applied to the transaction as it passes through the Gateway for a specific API. These policies may be organized in a linear fashion, executing in sequential order. Or, they may have conditional logic deciding which set of policies will execute depending on variables that are part of the API flow.

The Microgateway currently contains the following policies that run implicitly based on swagger definitions:

  • Client_ID/Client_Secret โ€“ Use a client ID and client secret to authenticate and authorize the use of this API
  • Basic Auth โ€“ Use Basic Auth to authenticate and authorize the use of this API
  • OAuth 2.0 โ€“ Use OAuth2.0 to authenticate and authorize the use of this API
  • Rate-Limit โ€“ Limit the number of requests per time unit that the subscriber may access this API

The Microgateway currently contains the following polices that are available to the Assembly extension to the swagger definition:

  • if - If a condition evaluates to True, execute the corresponding flow.
  • switch โ€“ Given a set of conditions, execute the flow corresponding to the first condition that evaluates to True.
  • operation-switch โ€“ Given a set of conditions on the operation, select the first rule where the condition evaluates to True.
  • throw โ€“ Throw an exception
  • invoke โ€“ Retrieve a resource using HTTP or HTTPS. Currently supported HTTP request methods or verbs are GET, HEAD, POST, PUT, PATCH, DELETE, and OPTIONS.
  • javascript โ€“ Execute a JavaScript program to manipulate or inspect the transaction
  • set-variable โ€“ Set a variable in the context

API Designer Toolkit

The API Designer toolkit provides a graphical interface for the Microgateway. You can download it using NPM via npm install -g apiconnect. This toolkit can be also be used for creating enterprise API definitions using IBM API Connect, which provides features to create and manage APIs on an enterprise scale.

For more information, see https://developer.ibm.com/apiconnect/.

The API designer toolkit creates YAML files for the APIs definitions. These can then be tested directly on the internal Microgateway (part of the API Designer toolkit), or you can run them on an external Microgateway by moving the underlying YAML files to the external Microgateway directory.

The Microgateway Architecture

The Microgateway was developed with the goal of making something simple, community-based, and that could easily be extended for anyoneโ€™s needs.

The Microgateway has the following characteristics:

  • Built on Node Express and Loopback frameworks
  • Processes Swagger API definitions via a middleware chain that identifies the API and executes the API definition.
  • Contains a โ€œdatastoreโ€ that holds the data model of all API artifacts to be processed.
  • Uses a flow-engine to process a variety of policies giving the API designer the ability to perform deep packet processing on the request or response.

A diagram of the Microgateway is shown below. Looking at the diagram, the flow of a request is from left to right. The Microgateway is a collection of middleware components that process the request in order. Each middleware component passes control to the next middleware until the processing of the request is complete. The postflow and error-handler middlewares work together to return the results back to the client making the request.

alt text

The urlrewrite middleware simply modifies the prefix of the URL under certain conditions. For the most part, this is a passthrough.

The context middleware creates a scratchpad memory area known as the context. The context is accessible by all middlewares and policies in the flow. Any middleware or policy can add, modify or remove variables from the context.

Here are some of the context variables that are automatically populated:

alt text

One object that is particularly important is the message object. The message object contains the payload that was received from a request. For example, if you add an invoke action, the results from that action will be placed in the message object. At the end of the flow, the contents of the message object will be returned back to the client.

Here are some other context variables:

alt text

The request object is another important object. It holds all of the information about the original request that was received by the Microgateway. There are other objects that contain system information, plan information, and general API information.

One important aspect of the context is that it is read-writable by policies and middleware as they execute. Another important factor is that context variables can be used as substitution parameters inside the conditional policies. This allows you to write sophisticated logic flows, simply referencing them through configuration.

The analytics middleware is used to connect to an external analytics engine. It passes a series of variables from the context in a message to an external collection device.

The preflow middleware accomplishes the following:

  1. Identifies the API (or Swagger definition) to execute.
  2. Performs security associated with that Swagger definition.
  3. Performs rate-limiting for the API.
  4. Creates the objects necessary for the assembly (IBM extensions to the swagger definition) to be consumed by the flow-engine.

The flow-engine is a combinational processor that allows you to insert sequential logic around a series of policies. The policies can perform any operation to the request or response payload. They can be used to retrieve a response from an API backend or examine the request for security or other needs.

The flow-engine is built as a vendor extension to the standard Swagger specification. The policies that are referenced in the assembly must have a pre-built policy. Each one of the policies is a Node.js module that provides the processing of the message. Each policy also has a policy.yml file that defines the set of properties and behavior of the policy. For examples, visit the policies directory of the microgateway repository.

Getting Started with the Microgateway

Following are the steps to install and run a stand alone microgateway

Step 1. Clone the microgateway repository

cd $HOME
git clone https://github.com/strongloop/microgateway.git

Step 2. Populate all of the necessary dependencies for the project

cd $HOME/microgateway
npm install

Step 3. Change current working directory to the root directory

cd $HOME/microgateway/

Step 4. Create a startup script that sets environment variables and starts up the Microgateway. The script file is a simple node.js JavaScript file shown below. Create this file in the $HOME/microgateway/ directory.

Note: The CONFIG_DIR is the folder containing the yaml files holding the API definitions that you wish to enforce.

// sample.js
//
'use strict';

var mg = require('./lib/microgw');
var fs = require('fs');

// config dir
process.env.CONFIG_DIR = __dirname + '/definitions/myapp';
process.env.NODE_ENV = 'production';
mg.start(3000);

Step 5. Create a yaml file to define the API. Place the yaml file in the folder identified by the CONFIG_DIR environment variable created in the startup script. For this example, we are creating the file sample_1.0.0.yaml in the $HOME/microgateway/definitions/myapp directory. Note that you can place several yaml files in this directory and all will be pulled in and used by the Microgateway.

# sample_1.0.0.yaml
#
info:
  version: 1.0.0
  title: sample
  description: sample laptop yaml
basePath: /sample
swagger: '2.0'
paths:
  /echo:
    get:
      responses:
        '200':
          description: 200 OK
x-ibm-configuration:
  assembly:
    execute:
      - javascript:
          title: write a small json object
          source: |
           message.body = { text : 'Hello World' };
schemes:
  - http

Step 6. From the root directory, execute the command to start the Microgateway.

cd $HOME/microgateway/
node sample.js

Step 7. Send a curl command to test the API. It should return the {โ€œtextโ€:โ€Hello Worldโ€} JSON object.

curl http://localhost:3000/sample/echo

For more information on the internal specifics of the Microgateway, you may want to look at the microgateway/test directory. All middleware components have one or more test suites to exercise their interfaces and logic.

For more examples on how to add various policies to your API assembly, look in the microgateway/test/definitions directory. There are several swagger files that are used to test out the implementation.

How to contribute to this Project

For information on contribuging to this project, please look at CONTRIBUTING.md and CONDUCT.md as well as the LICENSE.txt file.

More Repositories

1

loopback

LoopBack makes it easy to build modern applications that require complex integrations.
JavaScript
13,228
star
2

node-foreman

A Node.js Version of Foreman
JavaScript
1,257
star
3

strong-pm

deployer for node applications
JavaScript
998
star
4

loopback-example-access-control

An example demonstrating LoopBack access control mechanisms.
JavaScript
370
star
5

strongloop

StrongLoop: Enterprise Node to Power the API Economy
JavaScript
332
star
6

loopback-example-offline-sync

Offline sync, change tracking, and replication.
JavaScript
286
star
7

zone

Flow control and error handling for Node.js
JavaScript
279
star
8

loopback-example-user-management

LoopBack user management example
JavaScript
189
star
9

loopback-example-passport

LoopBack example for facebook login
HTML
186
star
10

generator-loopback

Yeoman generator that scaffolds out a LoopBack application
JavaScript
158
star
11

loopback-sdk-angular

Service for auto-generating Angular $resource services for LoopBack
JavaScript
155
star
12

loopback-component-passport

LoopBack passport integration to support third party logins and account linking
JavaScript
139
star
13

loopback-component-storage

Storage component for LoopBack.
JavaScript
130
star
14

strong-pubsub

PubSub for Node.js, Browser, Mobile and IoT
JavaScript
129
star
15

loopback-example-database

A tutorial for basic database related features.
JavaScript
120
star
16

strong-arc

StrongLoop Arc has been replaced by API Connect. We recommend Arc users move to the Essentials edition of API Connect. If you have questions, please email [email protected].
JavaScript
114
star
17

loopback-cli

LoopBack CLI tool for creating projects, models and more.
JavaScript
105
star
18

strong-remoting

Communicate between objects in servers, mobile apps, and other servers.
JavaScript
104
star
19

angular-live-set

Build realtime angular apps with html5's Server Sent Events
JavaScript
101
star
20

strong-cluster-control

cluster control module, allowing run-time control and monitoring of cluster
JavaScript
100
star
21

loopback-example-angular

A simple todo list using AngularJS on the client-side and LoopBack on the server-side.
JavaScript
97
star
22

loopback-component-push

Push notification component for LoopBack.
JavaScript
96
star
23

loopback4-example-microservices

Deprecated - please use https://github.com/strongloop/loopback4-example-shopping/tree/master/kubernetes
TypeScript
88
star
24

loopback-getting-started

Getting started example for LoopBack
TSQL
87
star
25

loopback-example-relations

Basic model relations concepts.
JavaScript
80
star
26

loopback-component-explorer

Browse and test your LoopBack app's APIs
JavaScript
71
star
27

loopback-example-ssl

An example to demonstrate how to set up SSL for LoopBack applications
JavaScript
69
star
28

loopback-getting-started-intermediate

JavaScript
68
star
29

loopback-example-facade

Best practices for building scalable Microservices.
JavaScript
67
star
30

strong-supervisor

Application supervisor that automatically adds cluster control and performance monitoring with StrongOps
JavaScript
66
star
31

loopback-boot

Convention-based bootstrapper for LoopBack applications
JavaScript
62
star
32

loopback-component-oauth2

oAuth 2.0 server for LoopBack
JavaScript
62
star
33

strong-agent

Profile, control, and monitor Node.js processes and clusters
JavaScript
61
star
34

strong-mq

MQ API with cluster integration, implemented over various message queues.
JavaScript
56
star
35

loopback-filters

implements LoopBack-style filtering.
JavaScript
55
star
36

modern-syslog

modern-syslog
JavaScript
49
star
37

loopback-example-app-logic

How to add your own business logic in a LoopBack app.
JavaScript
49
star
38

loopback-workspace

Manage a directory of LoopBack projects for a user, team, or organization
JavaScript
49
star
39

loopback-example-angular-live-set

Example of realtime angular app using html5 Server-sent events
JavaScript
48
star
40

strong-build

Build node packages into deployable applications
JavaScript
47
star
41

strong-oracle

Deprecated: Node.js Driver for Oracle databases (Use https://github.com/oracle/node-oracledb instead)
C++
45
star
42

loopback-swagger

LoopBack Swagger Spec Integration
JavaScript
44
star
43

loopback-example-storage

Example for loopback-component-storage.
HTML
43
star
44

supercluster

A module to make it easy to distribute work across multiple network-connected hosts.
JavaScript
30
star
45

loopback-sdk-angular-cli

CLI tools for auto-generating Angular $resource services for LoopBack
JavaScript
29
star
46

gulp-loopback-sdk-angular

gulp plugin for auto-generating Angular $resource services for LoopBack
JavaScript
27
star
47

apiconnect-docker

IBM API Connect on Docker
Shell
26
star
48

strong-globalize

strong-globalize is built on Unicode CLDR and jquery/globalize and implements automatic extraction of strings from JS source code and HTML templates, lint the string resource, machine-translate them in seconds. In runtime, it loads locale and string resource into memory and provides a hook to persistent logging.
JavaScript
25
star
49

loopback-context

Current context for LoopBack applications, based on node-continuation-local-storage
JavaScript
25
star
50

grunt-loopback-sdk-angular

Grunt plugin for auto-generating Angular $resource services for LoopBack
JavaScript
23
star
51

strong-cluster-socket.io-store

Implementation of socket.io store using node's native cluster messaging
JavaScript
23
star
52

loopback-connector-remote

LoopBack remote REST API connector
JavaScript
22
star
53

eslint-config-loopback

LoopBack's ESLint shareable configs.
20
star
54

strongloop-buildpacks

Shell
19
star
55

loopback-connector-swagger

Connect Loopback to a Swagger-compliant API
JavaScript
19
star
56

loopback-multitenant-poc

LoopBack Multitenancy PoC
JavaScript
19
star
57

flow-engine

JavaScript
18
star
58

loopback-example-mixins

Example app demonstrating mixins
JavaScript
17
star
59

eslint-config-strongloop

Baseline eslint configuration for StrongLoop modules
JavaScript
17
star
60

async-tracker

The AsyncTracker API is the JavaScript interface which allows developers to be notified about key events in the lifetime of observed objects and scheduled asynchronous events.
JavaScript
16
star
61

strong-express-metrics

An Express middleware for collecting HTTP statistics.
JavaScript
15
star
62

strong-store-cluster

JavaScript
14
star
63

strong-pubsub-example

Simple example app using strong-pubsub
JavaScript
14
star
64

strong-docs

build documentation sites for your node modules
TypeScript
14
star
65

loopback-connector-jsonrpc

Loopback Connector for JSONRPC
JavaScript
13
star
66

strong-deploy

Deploy nodejs applications
JavaScript
13
star
67

strong-data-uri

Parser and encoder for `data:` URIs
JavaScript
13
star
68

loopback-example-polyglot

Example LoopBack application with polyglot runtimes
JavaScript
13
star
69

loopback-example-push

Push notifications with LoopBack.
JavaScript
12
star
70

strong-task-emitter

JavaScript
11
star
71

strong-pubsub-redis

Redis adapter for strong-pubsub
JavaScript
11
star
72

strong-service-systemd

Generate an systemd service based on provided parameters
JavaScript
11
star
73

strong-cluster-connect-store

Implementation of connect store using node's native cluster messaging
JavaScript
11
star
74

strong-nginx-controller

Nginx controller for Arc
JavaScript
10
star
75

loopback-sandbox

A repository for reproducing LoopBack community issues.
JavaScript
10
star
76

loopback4-example-family-tree

An example LoopBack application to demonstrate OASGraph
TypeScript
10
star
77

strong-log-transformer

A stream filter for performing common log stream transformations like timestamping and joining multi-line messages.
JavaScript
10
star
78

strong-agent-statsd

publish strong-agent metrics to statsd
JavaScript
9
star
79

loopback-connector-db2iseries

Loopback connector for DB2 on iSeries
PLSQL
9
star
80

loopback-multitenancy

WORK IN PROGRESS: Multitenancy component for LoopBack.
JavaScript
9
star
81

strong-pubsub-mqtt

JavaScript
9
star
82

express-example-app

express example app for strong-pm
JavaScript
8
star
83

strong-config-loader

JavaScript
8
star
84

poc-loopback-multitenancy

Proof of concept for multitenancy in LoopBack.
JavaScript
8
star
85

strong-tools

Tools for packaging, releasing, and preparing npm modules
JavaScript
8
star
86

ephemeral-npm

Disposable npm server for testing packages
Shell
8
star
87

dist-paas-buildpack

StrongLoop distributions for PAAS
Shell
7
star
88

strong-service-install

Create/install system service for a given app
JavaScript
7
star
89

strong-service-upstart

Generate an upstart job based on provided parameters
JavaScript
7
star
90

strong-cluster-tls-store

Implementation of TLS session store using node's native cluster messaging
JavaScript
7
star
91

loopback-phase

Phase management for LoopBack applications.
JavaScript
7
star
92

loopback-oracle-installer

Loopback Oracle Installer
JavaScript
7
star
93

strong-module-loader

JavaScript
7
star
94

strong-pubsub-bridge

JavaScript
6
star
95

v4.loopback.io

LoopBack 4 Web Site
HTML
6
star
96

strong-tunnel

Disposable ssh proxy for TCP connections via URL
JavaScript
6
star
97

strong-pubsub-primus

Primus compatibility layer for strong-pubsub.
JavaScript
6
star
98

loopback-example-kv-connectors

LoopBack KeyValue connector examples.
JavaScript
6
star
99

strong-docker-build

Build a Docker image of an app run under strong-supervisor
JavaScript
6
star
100

loopback-oracle-builder

Loopback Oracle Builder
Shell
5
star