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

Improve adding defaults to WebClient requests [SPR-15208] #19772

Closed
spring-projects-issues opened this issue Jan 30, 2017 · 2 comments
Closed

Improve adding defaults to WebClient requests [SPR-15208] #19772

spring-projects-issues opened this issue Jan 30, 2017 · 2 comments
Assignees
Labels
in: web type: enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Jan 30, 2017

Rob Winch opened SPR-15208 and commented

It would be nice if there was a more elegant way to provide defaults for a request. For example, it would be nice if we could easily change the accept to JSON. The following is pretty verbose:

WebClient webClient = WebClient.create("http://localhost:" + port)
        .filter((request, next) -> {
            ClientRequest<Void> json = ClientRequest
                    .from(request)
                    .header("Accept", MediaType.APPLICATION_JSON_VALUE)
                    .build();
            return next.exchange(json);
        });

No further details from SPR-15208

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 30, 2017

Rossen Stoyanchev commented

Spring MVC Test has a "defaultRequest" feature in the MockMvc setup. I suppose this request here is in part inspired by that? Or at least is in comparison to that feature which is based on the same RequestBuilder for defining default and regular request, along with a merge of the two builder instances checking first if a request property has been set before merging it.

We now support the concept of a "base URI" in what is currently WebClientOperations. We could also allow declaring default headers and/or cookies to go with that base URI:

WebClient client = WebClient.builder()
        .baseUrl("http://localhost:"+ port)
        .defaultHeader("Accept", MediaType.APPLICATION_JSON_VALUE)
        .build();

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 1, 2017

Rossen Stoyanchev commented

I've updated the samples to match the latest refactoring WebClientOperations --> WebClient.

@spring-projects-issues spring-projects-issues added type: enhancement in: web labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.0 M5 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants