line/armeria

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

Aperta

#3707 aperta il 19 lug 2021

 (10 commenti) (4 reazioni) (1 assegnatario)Java (863 fork)batch import
good first issuenew feature

Metriche repository

Star
 (4552 stelle)
Metriche merge PR
 (Merge medio 5g 12h) (42 PR mergiate in 30 g)

Descrizione

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();

Guida contributor