line / armeria

Your go-to microservice framework for any situation, from the creator of Netty et al. You can build any type of microservice leveraging your favorite technologies, including gRPC, Thrift, Kotlin, Retrofit, Reactive Streams, Spring Boot and Dropwizard.
https://armeria.dev
Apache License 2.0
4.8k stars 912 forks source link

Provide a way to send a JSON object with `WebClient` #3707

Open ikhoon opened 3 years ago

ikhoon commented 3 years ago

JSON is the dominant exchange format for REST API. However, Armeria's WebClient does not provide any JSON-specific APIs. I believe it should be useful additions if we provide:

WebClient client = WebClient.of();
// Send a serialized JSON object with "applicaiton/json"
HttpResponse response = client.postJson("/items", new MyItem()); 
HttpResponse response = client.putJson("/items", new MyItem());
HttpResponse response = client.patchJson("/items", new MyItem());

HttpResponse response = client.prepare()
                              .post("/items")
                              .contentJson(new MyItem())
                              .execute();
0x1306e6d commented 3 years ago

Additionally, how do you think similar feature, HttpRequest.ofJson? Additionally, how about adding HttpRequest.ofJson also?

trustin commented 3 years ago

+1 to having HttpRequest.ofJson() as well.

ikhoon commented 3 years ago

It would also be nice to have APIs that automatically convert a response into an object.

interface HttpResponse {
  <T> CompletableFuture<T> aggregateAs(Class<? extends T> clazz);
  <T> CompletableFuture<T> aggregateAs(HttpStatus expectedStatus, Class<? extends T> clazz);
  <T> CompletableFuture<T> aggregateAs(HttpStatus expectedStatus, Class<? extends T> clazz, EventExecutor executor);
}
karellen-kim commented 3 years ago

I'm interested in this!

ikhoon commented 3 years ago

Thanks! It's all yours.