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

Stateful Options (eg Authentication) #1

Open
theduke opened this issue May 13, 2017 · 2 comments
Open

Stateful Options (eg Authentication) #1

theduke opened this issue May 13, 2017 · 2 comments
Assignees

Comments

@theduke
Copy link

theduke commented May 13, 2017

This library is a very cool idea.

One thing I would not know how to express: modifications that need to be made for each request, for example adding an Authentication header.

Any ideas how to express that smoothly?

@hephex
Copy link
Owner

hephex commented May 30, 2017

Hi @theduke, thank you 😄 Sorry if I didn't reply earlier.

ATM you can make the auth headers part of the struct that implements the Api trait,
but I see that it's not a nice solution, and it could create a lot of duplicate code.

I'd like to keep this issue open a try to find a good solution. One option could be transforming the Api into a sort of prototype that you can clone and customise every time, so if you need to reuse the same request several times with different headers, you can reuse part of the existing request. I'll look into it to see if it's a suitable solution.

What do you think?

@hephex
Copy link
Owner

hephex commented May 31, 2017

With this change, if you have an api request req you can use the method transform to create a request based on req that adds the header Authentication.

req.transform(
            |mut h: Headers| { h.insert("Authentication".to_string(), vec!["token123".to_string()]); h },
            identity::<Query>,
            identity::<io::Empty>
        );

Is this what you were looking for?

(I'll try to create a macro to make this transform nicer and readable.)

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

No branches or pull requests

2 participants