Kong/unirest-java

Making header method to avoid redundant typing.

rajmahendra opened this issue · 2 comments

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

No tasks being tracked yet.

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)

oops my bad. i have not seen that :)