http4s icon indicating copy to clipboard operation
http4s copied to clipboard

Look at other middleware for inspiration

Open rossabaker opened this issue 8 years ago • 13 comments

Let's look at other languages and see what we're missing. Many of them are trivial, and it's a great way to make a first contribution to the project. If you see one that you'd like, add it here. And better yet, grab it. We're here to help.

rossabaker avatar Aug 19 '18 04:08 rossabaker

Would there be interest in something like a ResponseTimer middleware, similar to express.js' response-time? Could use cats' Clock.

gstro avatar Oct 14 '18 00:10 gstro

Would this be different than the existing Prometheus Metrics and Dropwizard Metrics integrations? Also see #2131, for making a common metrics implementation with library-specific interpreters.

rossabaker avatar Oct 14 '18 00:10 rossabaker

Oh nice! I think my intention would be another "Simple middleware" like HeaderEcho for basic timing info without external metrics integrations. If those metrics are sufficient, I can look into other middleware to add.

gstro avatar Oct 14 '18 01:10 gstro

You mean like a middleware that returns an X-Response-Time header? I think this might be possible after #2131: instead of writing to a metrics backend, produce a header.

rossabaker avatar Oct 14 '18 02:10 rossabaker

Yep, just tacking on an X-Response-Time header was what I was thinking. If that's covered with the MetricsOps refactor, then that's great, but on first glance it looked like most of that work was on the client.

gstro avatar Oct 14 '18 02:10 gstro

The existing work has been on the client. The other ticket is to do similar for the server. Since the MetricsOps operations return F[Unit], I'm not sure it would work for a response header.

rossabaker avatar Oct 14 '18 16:10 rossabaker

Just peeked at the server metrics PR #2173, and the common MetricsOps return F[Unit] which is great for writing to a registry, but not a response header -- like you said.

Do you think it's worth it to put up a PR of a simple middleware for adding an X-Response-Time header?

gstro avatar Oct 14 '18 22:10 gstro

I'm open to it. One thing we struggled with on the server metrics: is response time the time until the header, or time until the entire response body is created? Both can be useful. You'll want to make clear what's being measured.

rossabaker avatar Oct 16 '18 00:10 rossabaker

Sounds good! I remember seeing that in the metrics PR too.

gstro avatar Oct 16 '18 06:10 gstro

@rossabaker would you be interested in a Http Method Overrider middleware (kinda like the Python's Django one)?

nebtrx avatar Jan 12 '19 19:01 nebtrx

@nebtrx Yes, that has proven useful in other languages.

rossabaker avatar Jan 13 '19 02:01 rossabaker

@nebtrx Yes, that has proven useful in other languages.

Cool! I just pushed a PR with that purpose. Please take a look at it and let me know how it goes.

nebtrx avatar Jan 13 '19 07:01 nebtrx

We got a couple out of this. I think it's served its purpose, but please don't hesitate to bring more useful ones.

rossabaker avatar Apr 05 '21 13:04 rossabaker