-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add request context to server service interface. #13
base: master
Are you sure you want to change the base?
Conversation
cc @sportnak |
We probably shouldn't be passing the Response object through. Calling |
I'm currently doing |
The request context contains the express request and response. This allows the server implementation to validate the authorization, for example.
8c99e52
to
271df02
Compare
Authentication is a cross-cutting concern that shouldn't need to be attached to every request, and especially not as a specific implementation of authentication. For example, I have a service that uses an API key in a header other than Authorization. I passed the Response object so that the service implementation could send headers. Another use case for this kind of API is distributed tracing. You might want some middleware that reads trace headers from the request, propagates them to dependencies, and adds them to responses. This API isn't easily composable. E.g. how could I add an authentication middleware and a tracing middleware to all service calls? Is there a better way? |
Is there any way we can do something like this with Express? I don't know Express very well, but instead of calling
|
If I'm tracking correctly, we do this in the ChmsAPI to pass authentication. We instantiate a new http client with the authorization headers from the request. https://git/Logos/ChmsApi/blob/master/src/chmsService.ts#L285 If the https://git/Logos/ChmsApi/blob/master/server.ts#L18 Let me know if I'm missing something here. |
As @ddunkin mentioned, having an In my example, |
Right, I was thinking that headers could be passed in as part of the request object that goes down to the service. In that way, you can use different headers in different requests. This could be done in the |
I still feel strongly that the interface should be the same for the client and the server, which is one of the core architectural principles of Facility. The ideal service interface implementation is entirely abstracted from the web service framework. I'm not yet convinced that my suggestion would be an undue burden on implementors. |
Like that? 32cb5b8 |
I love it! |
Yeah this makes sense. Pretty similar to how we're using it now, and the interface is the same for client and server still. 👍 |
The request context contains the express request and response. This allows the server implementation to validate the authorization, for example.
I'm interested in other ideas to address this issue. Seems like we rely on thread-local storage and/or per-request instances of the service implementation with ASP.NET, neither of which are idiomatic for node.js/express.