bastion-dev / Bastion

Java test library for HTTP APIs
http://bastion.rocks
GNU General Public License v3.0
13 stars 8 forks source link

Add GET request utility method to JsonRequest #72

Closed FrelliBB closed 7 years ago

FrelliBB commented 7 years ago

JsonRequest requires a JsonRequest.get(url) utility method which functions the same way as GeneralRequest.get() but sets the content type to application/json.

This will also allow the .bind() to properly decode the model of the response from the GET into its json representation. The current alternative to this is using GeneralRequest.get(url).setContentType("application/json").

KPull commented 7 years ago

I don't really agree with this. This is by design. You're not meant to have any content-type when the body is empty (more so, when sending a GET request since there's no entity).

The flaw, in this case, is in the server. In fact, the request data and bind() have nothing to do with each other since bind() deals with the response. The server is choosing to send data depending on the request's Content-type. If you really want to set the content-type on a request containing no body then I feel like GeneralRequest.get(url).setContentType("application/json") is enough.

In the HTTP standard, the expected response type is usually specified using the Accept header.

FrelliBB commented 7 years ago

Turns out this was actually a bug in my code where I had a @Consumes("application/json") on a @GET method! My server was sending a 415 Unsupported Media Type error and thus the .bind() was failing.

However this does uncover the issue that if .bind() fails, the response that the server sent is not logged anywhere. I did not realise at any point that my server was sending a 415.

FrelliBB commented 7 years ago

Opened a separate issue for this here https://github.com/bastion-dev/Bastion/issues/73