serverless / event-gateway

React to any event with serverless functions across clouds
https://www.serverless.com/event-gateway
Apache License 2.0
1.65k stars 97 forks source link

[Docs] Extendable Middleware #105

Closed austencollins closed 7 years ago

austencollins commented 7 years ago

Many API Gateway implementations have extendable middleware (e.g., Kong Plug-ins). How could we add this to the current implementation?

Example Use-Cases:

mthenw commented 7 years ago

IMHO for mentioned use cases, we need two different things: plugins & middlewares.

Plugins

Plugins: something that extends the gateway on a low-level, giving access to internal structures, and many integration points. It's a low-level access that's why it's fast and might be used without heavily influencing overall perf (Tyler will kill me for that statement :D). Implementation options:

Middleware

Serverless function that runs before some other function and has the ability to change parameters/context or result. Simple to implement: during function registration, a user can specify pre/post middleware/hook. A middleware/hook is a function from the discovery:

Example register function payload:

{
  "functionId": "grapqh",
  "awsLambda": {
    ...
  },
  "middlewares": {
    "pre": "auth"
  }
}

Maybe "hooks" is not the best name, maybe middleware