Kong / unirest-java

Unirest in Java: Simplified, lightweight HTTP client library.
http://kong.github.io/unirest-java/
MIT License
2.58k stars 591 forks source link

Making header method to avoid redundant typing. #521

Closed rajmahendra closed 3 months ago

rajmahendra commented 3 months ago

Is your feature request related to a problem? Please describe. Not a problem but redundancy in the api a user keep doing and it can create a spelling mistake when typing. ex. .header("Accept", "application/json") .header("Content-Type", "application/json")

Describe the solution you'd like instead of this the user keep writing Accept Content-Type application/json etc we can provide a static final method or/and methods like headerAccept()"" headerContentTpe("") this reduces typos in coding and the code look clean

Describe alternatives you've considered the pplication/json can be a string constants or enum . We can add the above new methods with header() so user can pick what they want. so this can comparable with versions.

### Tasks
ryber commented 3 months ago

Unirest actually has convenience methods for accept and content type headers already. It also has a ContentType class, with the major types. What it didn't have was a way to use those mediatypes directly with the method without adding toString() so I just added that. Available in 4.3.1

 Unirest.post("http://localhost")
                .accept(ContentType.IMAGE_JPEG)
                .contentType(ContentType.APPLICATION_JSON)
rajmahendra commented 3 months ago

oops my bad. i have not seen that :)