Skip to content

Commit 61769ce

Browse files
committed
fixing table of contents
1 parent e65c902 commit 61769ce

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

docs/README.md

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ A super fast, framework agnostic Node.js API Gateway for the masses ❤️
1414
Read more online:
1515
- A “.js” API Gateway for the masses: https://itnext.io/a-js-api-gateway-for-the-masses-a12fdb9e961c
1616

17-
## Install
17+
# Install
1818
```js
1919
npm i fast-gateway
2020
```
2121

22-
## Usage
22+
# Usage
2323
Next we describe two examples proxying HTTP and Lambda downstream services.
2424
> For simplicity of reading, both examples are separated, however a single gateway configuration supports all routes configurations.
25-
### HTTP proxying
26-
#### Gateway
25+
## HTTP proxying
26+
### Gateway
2727
```js
2828
const gateway = require('fast-gateway')
2929
const server = gateway({
@@ -35,16 +35,16 @@ const server = gateway({
3535

3636
server.start(8080)
3737
```
38-
#### Remote Service
38+
### Remote Service
3939
```js
4040
const service = require('restana')()
4141
service.get('/get', (req, res) => res.send('Hello World!'))
4242

4343
service.start(3000)
4444
```
4545

46-
### AWS Lambda proxying
47-
#### Gateway
46+
## AWS Lambda proxying
47+
### Gateway
4848
```bash
4949
npm i http-lambda-proxy
5050
```
@@ -65,7 +65,7 @@ server.start(8080)
6565
```
6666
> You might also want to read: [Setting AWS Credentials in Node.js](https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-credentials-node.html)
6767
68-
#### Function implementation
68+
### Function implementation
6969
```js
7070
const serverless = require('serverless-http')
7171
const json = require('serverless-json-parser')
@@ -87,7 +87,7 @@ module.exports.handler = serverless(service)
8787

8888
```
8989

90-
## Configuration options explained
90+
# Configuration options explained
9191
```js
9292
{
9393
// Optional server instance. Any HTTP framework that supports the following signature is compatible:
@@ -177,10 +177,10 @@ module.exports.handler = serverless(service)
177177
}]
178178
}
179179
```
180-
### Hooks
180+
## Default hooks
181181
For developers reference, default hooks implementation are located in `lib/default-hooks.js` file.
182182

183-
## The "*GET /services.json*" endpoint
183+
# The "*GET /services.json*" endpoint
184184
Since version `1.3.5` the gateway exposes minimal documentation about registered services at: `GET /services.json`
185185

186186
Example output:
@@ -201,7 +201,7 @@ Example output:
201201
```
202202
> NOTE: Please see `docs` configuration entry explained above.
203203
204-
## WebSockets support
204+
# WebSockets
205205
WebSockets proxying is supported since `v3.1.0`. Main considerations:
206206
- The `faye-websocket` module dependency require to be installed:
207207
```bash
@@ -229,7 +229,7 @@ WebSockets proxying is supported since `v3.1.0`. Main considerations:
229229
```
230230
- The `/` route prefix is considered the default route.
231231

232-
#### Configuration example
232+
## Configuration example
233233
```js
234234
gateway({
235235
routes: [{
@@ -241,8 +241,8 @@ gateway({
241241
}]
242242
}).start(PORT)
243243
```
244-
## Traffic Management
245-
### Timeouts and Unavailability
244+
# Traffic Management
245+
## Timeouts and Unavailability
246246
We can restrict requests timeouts globally or at service level using the `timeout` configuration.
247247

248248
You can also define endpoints specific timeout using the property `timeout` of the request object, normally inside a middleware:
@@ -251,12 +251,12 @@ req.timeout = 500 // define a 500ms timeout on a custom request.
251251
```
252252
> NOTE: You might want to also check https://www.npmjs.com/package/middleware-if-unless
253253
254-
### Circuit Breakers
254+
## Circuit Breakers
255255
By using the `proxyHandler` hook, developers can optionally intercept and modify the default gateway routing behavior right before the origin request is proxied to the remote service. Therefore, connecting advanced monitoring mechanisms like [Circuit Breakers](https://martinfowler.com/bliki/CircuitBreaker.html) is rather simple.
256256

257257
Please see the `demos/circuitbreaker.js` example for more details using the `opossum` library.
258258

259-
### Rate Limiting
259+
## Rate Limiting
260260
[Rate limiting](https://en.wikipedia.org/wiki/Rate_limiting), as well many other gateway level features can be easily implemented using `fast-gateway`:
261261
```js
262262
const rateLimit = require('express-rate-limit')
@@ -288,7 +288,7 @@ gateway({
288288
```
289289
> In this example we have used the [express-rate-limit](https://www.npmjs.com/package/express-rate-limit) module.
290290
291-
## Hostnames support
291+
# Hostnames support
292292
We can also implement hostnames support with fast-gateway, basically we translate hostnames to prefixes:
293293
```js
294294
...
@@ -338,17 +338,17 @@ const hostnames2prefix = [{
338338
```
339339
For more details, please checkout the `basic-hostnames.js` demo.
340340

341-
## Gateway level caching
341+
# Caching
342342
Caching support is provided by the `http-cache-middleware` module. https://www.npmjs.com/package/http-cache-middleware
343343

344-
### Introduction
344+
## Introduction
345345
Enabling proper caching strategies at gateway level will drastically reduce the latency of your system,
346346
as it reduces network round-trips and remote services processing.
347347
We are talking here about improvements in response times from `X ms` to `~2ms`, as an example.
348348
> We use the `http-cache-middleware` module to support gateway level caching. Read more about it: https://github.com/jkyberneees/http-cache-middleware
349349
350-
### Setting up gateway level cache available for all services
351-
#### Single node cache (memory)
350+
## Caching responses from all services
351+
### Single node cache (memory)
352352
```js
353353
// cache middleware
354354
const cache = require('http-cache-middleware')()
@@ -361,7 +361,7 @@ const server = gateway({
361361
```
362362
> Memory storage is recommended if there is only one gateway instance and you are not afraid of losing cache data.
363363
364-
#### Multi nodes cache (redis)
364+
### Multi nodes cache (redis)
365365
```js
366366
// redis setup
367367
const CacheManager = require('cache-manager')
@@ -388,13 +388,13 @@ const server = gateway({
388388
```
389389
> Required if there are more than one gateway instances
390390
391-
### Caching remote services response
391+
## Enabling caching on remote services
392392
https://github.com/jkyberneees/http-cache-middleware#enabling-cache-for-service-endpoints
393393

394-
### Invalidating caches
394+
## Cache invalidation
395395
https://github.com/jkyberneees/http-cache-middleware#invalidating-caches
396396

397-
### Custom cache keys
397+
## Custom cache keys
398398
Cache keys are generated using: `req.method + req.url`, however, for indexing/segmenting requirements it makes sense to allow cache keys extensions.
399399
Unfortunately, this feature can't be implemented at remote service level, because the gateway needs to know the entire lookup key when a request
400400
reaches the gateway.
@@ -412,7 +412,7 @@ routes: [{
412412
```
413413
> In this example we also distinguish cache entries by `user.id`, very common case!
414414
415-
### Enabling/Disabling cache
415+
## Disabling caching programmatically
416416
You can also disable cache checks for certain requests programmatically:
417417
```js
418418
routes: [{
@@ -425,25 +425,25 @@ routes: [{
425425
}]
426426
```
427427

428-
## Related projects
428+
# Related projects
429429
- middleware-if-unless (https://www.npmjs.com/package/middleware-if-unless)
430430
- fast-proxy-lite (https://www.npmjs.com/package/fast-proxy-lite)
431431
- http-lambda-proxy (https://www.npmjs.com/package/http-lambda-proxy)
432432
- restana (https://www.npmjs.com/package/restana)
433433

434-
## Benchmarks
434+
# Benchmarks
435435
https://github.com/jkyberneees/nodejs-proxy-benchmarks
436436

437-
## Sponsors
437+
# Sponsors
438438
- (INACTIVE) Kindly sponsored by [ShareNow](https://www.share-now.com/), a company that promotes innovation!
439439

440-
## Support / Donate 💚
440+
# Support / Donate 💚
441441
You can support the maintenance of this project:
442442
- PayPal: https://www.paypal.me/kyberneees
443443
- [TRON](https://www.binance.com/en/buy-TRON) Wallet: `TJ5Bbf9v4kpptnRsePXYDvnYcYrS5Tyxus`
444444

445-
## Breaking Changes
446-
### v3.x
445+
# Breaking Changes
446+
## v3.x
447447
- The `fast-proxy-lite` module is used by default to support `http` proxy type 🔥. This means, no `undici` or `http2` are supported by default.
448448
- The old `fast-proxy` module is available under the `http-legacy` proxy type, but the module is not installed by default.
449449
- Proxy configuration is now generalized under the `proxyConfig` property.

0 commit comments

Comments
 (0)