@Immutable public interface Request
Instance of this class is supposed to be used this way:
String name = new ApacheRequest("https://www.example.com:8080") .uri().path("/users").queryParam("id", 333).back() .method(Request.GET) .header(HttpHeaders.ACCEPT, MediaType.TEXT_XML) .fetch() .as(HttpResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .as(XmlResponse.class) .assertXPath("/page/links/link[@rel='see']") .rel("/page/links/link[@rel='see']/@href") .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON) .fetch() .as(JsonResponse.class) .json().getJsonObject().getString("name");
Since version 0.10 it is recommended to use
RetryWire
decorator to avoid accidental IOException
when connection is weak
or unstable, for example:
String body = new JdkRequest("https://www.google.com") .through(RetryWire.class) .fetch() .body();
Instances of this interface are immutable and thread-safe.
JdkRequest
,
ApacheRequest
Modifier and Type | Field and Description |
---|---|
static String |
DELETE
DELETE method name.
|
static String |
GET
GET method name.
|
static String |
HEAD
HEAD method name.
|
static String |
OPTIONS
OPTIONS method name.
|
static String |
PATCH
PATCH method name.
|
static String |
POST
POST method name.
|
static String |
PUT
PUT method name.
|
Modifier and Type | Method and Description |
---|---|
RequestBody |
body()
Get request body.
|
Response |
fetch()
Execute it with a specified HTTP method.
|
Request |
header(String name,
Object value)
Set request header.
|
Request |
method(String method)
Use this method.
|
Request |
reset(String name)
Remove all headers with this name.
|
<T extends Wire> |
through(Class<T> type,
Object... args)
Send it through a decorating
Wire . |
RequestURI |
uri()
Get destination URI.
|
static final String GET
static final String POST
static final String PUT
static final String HEAD
static final String DELETE
static final String OPTIONS
static final String PATCH
@NotNull(message="URI is never NULL") RequestURI uri()
@NotNull(message="request is never NULL") RequestBody body()
@NotNull(message="request is never NULL") Request header(@NotNull(message="header name can\'t be NULL") String name, @NotNull(message="header value can\'t be NULL") Object value)
name
- ImmutableHeader namevalue
- Value of the header to set@NotNull(message="alternated request is never NULL") Request reset(@NotNull(message="header name can\'t be NULL") String name)
name
- ImmutableHeader name@NotNull(message="request is never NULL") Request method(@NotNull(message="method can\'t be NULL") String method)
method
- The method to useResponse fetch() throws IOException
IOException
- If fails to fetch HTTP requestCopyright © 2012–2014 jcabi.com. All rights reserved.