CrowdHailer / raxx

Interface for HTTP webservers, frameworks and clients
https://hexdocs.pm/raxx
Apache License 2.0
402 stars 29 forks source link

Add middleware example #90

Closed lpil closed 6 years ago

lpil commented 6 years ago

There's a lot of issues suggesting some useful sounding middleware, but there is no example of what the middleware format it and how the user composes them together.

Could you add an example so that we can start contributing middlewares? :)

CrowdHailer commented 6 years ago

There is still some flexibility about how middleware is defined. I have some idea's but not 100% sure what is the best solution, because the implementation of checking some request headers may be very different to counting the number of response chunks. For that reason I have deliberately avoided describing a middleware framework. This is my favourite approach so far https://github.com/CrowdHailer/raxx_method_override/blob/master/lib/raxx/method_override.ex#L101-L117

That said if you are not interested in streaming then you can follow this guide. https://github.com/CrowdHailer/Tokumei/blob/master/guides/writing-middleware-with-macros.md

I believe @samphilipd has written some middleware that just works with handle_request?

CrowdHailer commented 6 years ago

@lpil is the logger example enough to be working with https://github.com/CrowdHailer/raxx/blob/master/lib/raxx/logger.ex