Skip to content

Allow ClientHttpRequestFactory to create a request using a URI template #34078

@kk-mats

Description

@kk-mats

Summary

This is an enhancement request to add uriTemplate parameter in the arguments of ClientHttpRequestFactory#createRequest.

Background

In RESTful principal, it is strongly recommended to include ID as a path parameter of the path of endpoint interacting with a specific resource e.g. /users/{userId}.
Thus, rather than the actual path like /users/john, the URI template needs to be checked to apply endpoint specific configuration inside ClientHttpRequestFactory#createRequest using underlying client library such as timeout or logging.

Problem

Currently the method has only two arguments, URI and HttpMethod.

Due to this, my ClientHttpRequestFactory implementation needs to look up per endpoint configuration by matching URI and URI templates while the given URI is created from the endpoint's URI template.

// load endpoint configs from the property file
// Actual implemention considers http method as well but I omitted it here as it is not related here.
var endpointConfigs = Map.of(uriTemplate, endpointConf).

endpointConfigs.entrySet()
    .stream()
    .filter((template, config) -> UriTemplate.matches(template, uri))
    .first()
    .ifPresent(_, config) -> config.apply(request)).

Once uriTemplate is introduced the above code can be replaced with

var endpointConfigs = Map.of(uriTemplate, endpointConf).
endpointConfigs.get(uriTemplate).apply(request).

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions