Skip to content

Add possibility to pass request headers to HttpClient #790

@porunov

Description

@porunov

Right now the generated HttpClient interface looks like the next one:

export interface HttpClient {
    request<R>(requestConfig: { method: string; url: string; queryParams?: any; data?: any; copyFn?: (data: R) => R; }): RestResponse<R>;
}

The interface lacks a possibility to accept request headers which might be sometimes used to represent some incoming arguments.
For example, in Spring you would typically define the next arguments to accept headers in your controller:

@GetMapping(value = "/test")
public ResponseEntity<ResponseEntity> test(
        @RequestHeader("first-header") Integer argument1,
        @RequestHeader("second-header") String argument2) {
    return null;
}

Right now, both arguments Integer argument1 and String argument2 are ignored.

It would be great to add possibility to register header arguments as well and be able to pass them into HttpClient.

I'm not that familiar with the code base right now but I guess that we should do something like the next:

  • Add headers collection in RestMethodModel. I guess something like private final List<MethodParameterModel> headerParams; should be enough.
  • Add headers resolution logic into ModelCompiler.processRestMethod.
  • Add possibility to accept headers in HttpClient.

If combined with #788 then this may be enough for any user to register custom headers on it's own if needed.
Without #788 the below steps might be necessary as well.

Another (optional) task might be related to detecting Spring @RequestHeader automatically (without using custom logic via #788). So, I would think about steps like the next:

  • Optionally add a parameter in Settings which enables headers resolution logic (in case someone would like to omit this feature for any reason).
  • Add annotation detection logic into SpringApplicationParser.parseControllerMethod.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions