Express Gateway has a lot of powerful features beyond just auth. Another important feature is rate limiting, which throttles requests to one or more endpoints. Express Gateway has a lot of tuneable options for configuring throttling: you can throttle requests on a per user, per endpoint, or per pipeline basis. In this article, I'll walk you through a "Hello, World" example of using Express Gateway's rate limiting policy, and then show a practical use case of rate limiting based on user API keys.
const Archetype = require('archetype'); | |
const assert = require('assert'); | |
const RequestType = new Archetype({ | |
service: { | |
$type: 'string', | |
$required: true | |
}, | |
// `location` is implicitly `$required` because | |
// `type` and `coordinates` are `$required` |
const Archetype = require('archetype'); | |
const express = require('express'); | |
const superagent = require('superagent'); | |
const app = express(); | |
const Params = new Archetype({ | |
names: { $type: ['string'], $default: [] } | |
}).compile('Params'); | |
app.get('/', function(req, res) { |
Express Gateway has built-in support for numerous authentication mechanisms, like OAuth2 and key auth. On top of these authentication mechanisms, Express Gateway supports restricting access to certain endpoints to certain users using the notion of scopes. In this article, I'll provide a "Hello, World" example of using scopes and then dive into a more realistic example of using scopes to protect access to an external API.
Express Gateway comes with a lot of powerful features baked in, like OAuth2 and key auth. When built-in features aren't enough, Express Gateway has an expression policy, which lets you execute arbitrary JavaScript to modify the request and response. In this article, I'll show you how the expression policy works with several sample use cases.
To get started, let's create a basic expression: one that returns an
Express Gateway gives you the ability to spin up your own oauth provider from the command line. Oauth enables your users to delegate API endpoints to various apps via scopes. In this introductory article, you'll learn how to get up and running with Oauth in Express Gateway.
const Keen = require('keen-js'); | |
const Mailgun = require('mailgun-js'); | |
const bodyParser = require('body-parser'); | |
const express = require('express'); | |
const app = express(); | |
app.use(bodyParser.json()); | |
const keys = { | |
// Top-level is the gateway's API keys, so user will send `token-1` to the |
// MongoDB 2.6, Linux Mint 17.1, node driver HEAD | |
/* Output looks like: | |
``` | |
nextObject returned | |
Calling nextObject again... | |
Calling execGetMore | |
``` | |
The `console.log('second nextObject returned');` line never gets executed and the program exits because of no listeners |
var http = require('http'); | |
var request = require('request'); | |
var addrs = [ | |
'http://127.0.0.1:3000', | |
'http://127.0.0.1:3001' | |
]; | |
var index = 0; | |
http.createServer(function(req, res) { |