Skip to content
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

Middleware (hooks) #29

Open
cyberhck opened this issue Feb 19, 2018 · 2 comments
Open

Middleware (hooks) #29

cyberhck opened this issue Feb 19, 2018 · 2 comments

Comments

@cyberhck
Copy link

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 🙂

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 :)

@hgoebl
Copy link
Owner

hgoebl commented Feb 19, 2018

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 :-)

@cyberhck
Copy link
Author

Sure, that was just reflex because I was doing a lot of Golang these days 😄 I'll look at the existing codebase and do the code style accordingly 🙂 and again, thanks for responding really fast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants