Middleware vs Other Approaches #186
Replies: 2 comments
-
Personally, I would vote in favor of a mix of options A and B. I think the main logic of each of these middleware functions should be abstracted out into their own utility functions, and then we can create a single middleware function that targets the registration endpoints and runs all 3 of the utility functions. Abstracting out the core logic makes it easier to test those parts in isolation, and it will make it easier to implement that functionality for the |
Beta Was this translation helpful? Give feedback.
-
Update: It seems we're all in agreement on a path forward, so I've created issue #189 to address this. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Overview
@jsstevenson brought up a great question about how AnyVar is currently utilizing middleware: is middleware the most appropriate approach for logic that's only needed for a small number of endpoints, given that middleware triggers for every request for every endpoint?
Currently we have 3 middleware functions that are either already in production, or are under active development:
add_creation_timestamp_annotation
/variation
(though I think it should also target
/vrs_variation
?)add_genomic_liftover_annotation
/variation
/vrs_variation
store_input_payload_annotation
/variation
/vrs_variation
All of the above only target the same two endpoints used to register variants.
Potential Concerns
Middleware functions trigger on EVERY request, whether the endpoint is one that your logic intends to target or not. You have to remember to put in checks for each middleware function to ensure the logic only runs for the desired endpoints.
Each of these middleware functions parse and rebuild the response object when they run, meaning that this parsing/rebuilding occurs 3 times whenever one of the variant registration endpoints is hit. 3 times isn't the end of the world as far as performance goes, but it could become an issue down the line if we continue with this pattern.
Alternative Options
Discussion Points
Thanks for your feedback!
Beta Was this translation helpful? Give feedback.
All reactions