|
1 | 1 | # Responses |
2 | | -Unirest makes the actual request the moment you invoke of it's ```as[type]``` method. These methods also inform Unirest what type to map the response to. Options are ```Empty```, ```String```, ```File```, ```Object```, ```byte``` and ```Json```. |
| 2 | +Unirest makes the actual request the moment you invoke one of its ```as[type]``` methods. These methods also inform Unirest what type to map the response to. Options are ```Empty```, ```String```, ```File```, ```Object```, ```byte``` and ```Json```. |
3 | 3 |
|
4 | 4 | The response returns as a ```HttpResponse<T>``` where the ```HttpResponse``` object has all of the common response data like status and headers. The Body (if present) can be accessed via the desired type with the ```.getBody()``` method. |
5 | 5 |
|
6 | 6 | ## Empty Responses |
7 | | -If you aren't expecting a body back, ```asEmpty``` is the easiest choice. You will still get back response information like status and headers. |
| 7 | +If you aren't expecting a body back, or you don't care about the body, ```asEmpty``` is the easiest choice. You will still get back response information like status and headers. Note that this method effectively ignores any body that might be present. |
8 | 8 |
|
9 | 9 | ```java |
10 | | -HttpResponse response = Unirest.delete("http://localhost").asEmpty() |
| 10 | +HttpResponse response = Unirest.delete("http://localhost").asEmpty(); |
11 | 11 | ``` |
12 | 12 |
|
13 | 13 | ## String Responses |
14 | 14 | The next easiest response type is String. You can do whatever you want with it after that. |
15 | 15 |
|
16 | 16 | ```java |
17 | 17 | String body = Unirest.get("http://localhost") |
18 | | - .asString() |
19 | | - .getBody(); |
| 18 | + .asString() |
| 19 | + .getBody(); |
20 | 20 | ``` |
21 | 21 |
|
22 | 22 | ## Object Mapped Responses |
23 | 23 | Most of the time when consuming RESTful services you probably want to map the response into an object. |
24 | 24 |
|
25 | | -For this you need to provide the Unirest configuration with a implementation of ```ObjectMapper``` (see [Object Mappers](#object-mappers) for details.). |
| 25 | +For this you need to provide the Unirest configuration with an implementation of ```ObjectMapper``` (see [Object Mappers](#object-mappers) for details.). |
26 | 26 |
|
27 | | -If the response is JSON you are in luck and Unirest comes with a basic ```JsonObjectMapper``` basic on Google GSON |
| 27 | +If the response is JSON you are in luck and Unirest comes with a basic ```JsonObjectMapper``` based on Google GSON. |
28 | 28 |
|
29 | 29 | Before an `asObject(Class)` it is necessary to provide a custom implementation of the `ObjectMapper` interface (if you do not wish to use the default mapper). This should be done only the first time, as the instance of the ObjectMapper will be shared globally. |
30 | 30 |
|
|
0 commit comments