You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Authorization (is the client allowed to call this endpoint?)
Rate/concurrency limiting per client type
Timeouts
Logging
These generally need to run before and sometimes after every request, and in some cases make a decision about whether the request is allowed to happen. Web servers have similar needs that are served with a middleware framework like Plug, or Rack in the Ruby world. I propose we have a middleware framework for elixir-thrift.
When creating the server, we'd pass an additional option like:
When handling a request, the server would call the first middleware with a callback function to invoke the subsequent chain of middleware. The last middleware's callback function will invoke the normal, existing request handling. A stub middleware implementation would look like this:
defmoduleStubMiddlewaredodefhandle_request(request,func)do# <- Before subsequent middlewares have been called.response=func(request)# <- After subsequent middlewares have been called.responseendend
We'd have a handful of standard middleware types available for common things like logging, but this would also provide an extension point for users to implement custom ones. For instance we want to authorize every request using a proprietary system with which it wouldn't make sense to integrate elixir-thrift directly.
The request object would be a struct. Spitballing:
I like and use middleware a lot, but defining a fixed list of middleware for every call could be a bit inflexible. We actually don't need any specific support to add middleware to every call, we can just do it manually and it's even more flexible. E.g. from the readme,
This middleware can do anything with the given arguments--log them, use them for access control purposes, etc. The middlewares can be nested or composed together to create middleware stacks that do everything you need.
But you may be thinking, this would require manually injecting the middleware into every handler. In fact, with Elixir macros it should be fairly easy to have e.g. a defthrift macro that defines a handler and applies a middleware stack to it at the same time. Then just replace def with defthrift.
There are several kinds of standard functionality we need to apply on every Thrift endpoint.
These generally need to run before and sometimes after every request, and in some cases make a decision about whether the request is allowed to happen. Web servers have similar needs that are served with a middleware framework like Plug, or Rack in the Ruby world. I propose we have a middleware framework for elixir-thrift.
When creating the server, we'd pass an additional option like:
When handling a request, the server would call the first middleware with a callback function to invoke the subsequent chain of middleware. The last middleware's callback function will invoke the normal, existing request handling. A stub middleware implementation would look like this:
We'd have a handful of standard middleware types available for common things like logging, but this would also provide an extension point for users to implement custom ones. For instance we want to authorize every request using a proprietary system with which it wouldn't make sense to integrate elixir-thrift directly.
The request object would be a struct. Spitballing:
The text was updated successfully, but these errors were encountered: