DavidWebb
DavidWebb copied to clipboard
Middleware (hooks)
Hi there, I'm using this project for my android project. And I wanted to implement a JWT token middleware which will automatically refresh a JWT if it was expired and then continue with the response. Coming across the readme, I found out that beforeSend and afterReceive are planned and are in Todo.
Coming from Golang/TypeScript world, I'd suggest something like this:
webb.AddMiddlware(jsonMiddleware)
Middleware implements an interface with method handle() which receives the original request and the next handler function
Now middleware can choose to either call the next or entirely skip, or maybe even modify the original request before continueing. Let me know if that makes sense :slightly_smiling_face:
This one will totally resolve the necessity of the following todos:
- decorator/interceptor beforeSend - provide hooks to manipulate request before send
- decorator/interceptor afterReceive - provide hooks to manipulate raw response after receiving it
Let me know if you'll be willing to accept PRs :)
Sounds like a good idea.
I'm willing to accept PRs. Please use .addMiddleware
instead of .AddMiddleware
. In TypeScript, JavaScript and Java it's totally uncommon to name methods starting upper-case.
Would be nice if your PR contains unit-tests and doesn't break other tests.
Cheers :-)
Sure, that was just reflex because I was doing a lot of Golang these days :smile: I'll look at the existing codebase and do the code style accordingly :slightly_smiling_face: and again, thanks for responding really fast.