Skip to content

[http-client] Add @Headers Annotation #402

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

Merged
merged 2 commits into from
Mar 15, 2024
Merged

Conversation

SentryMan
Copy link
Collaborator

Adds something like Retrofits @Headers (I got sick of making default methods to add preset headers)

Now we can do stuff like this:

@Client
@Headers("Content-Type: applicaton/json")
public interface TitanFall {

  @Get("/${titan}/${drop.point}")
  @Headers("Something: \\invalid\n\t")
  Titan titanFall();


  @Get("/${titan}/copium")
  @Headers("      Accept    :   applicaton/json")
  Titan titanFall3();
}

and the generated class will have

  // GET /${titan}/${drop.point}
  private static final String DROP_POINT = System.getProperty("drop.point");
  private static final String TITAN = System.getProperty("titan");
  @Override
  public Titan titanFall() {
    return client.request()
      .header("Something", "\\invalid")
      .header("Content-Type", "applicaton/json")
      .path(TITAN).path(DROP_POINT)
      .GET()
      .bean(Titan.class);
  }

  // GET /${titan}/copium
  @Override
  public Titan titanFall3() {
    return client.request()
      .header("Accept", "applicaton/json")
      .header("Content-Type", "applicaton/json")
      .path(TITAN).path("copium")
      .GET()
      .bean(Titan.class);
  }

@SentryMan SentryMan self-assigned this Mar 15, 2024
@SentryMan SentryMan requested a review from rbygrave March 15, 2024 02:20
@SentryMan SentryMan added the enhancement New feature or request label Mar 15, 2024
@SentryMan SentryMan added this to the 2.3 milestone Mar 15, 2024
@rbygrave rbygrave merged commit 8c864ae into avaje:master Mar 15, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants