HttpRequest and HttpResponse
All 3 Akka HTTP Client API levels use the same basic model of HttpRequest
and HttpResponse
.
Creating requests
You can create simple GET
requests:
- Scala
- Java
-
source
HttpRequest.create("https://akka.io"); // with query params HttpRequest.create("https://akka.io?foo=bar");
Note
HttpRequest
’s method HttpRequest::withUri()
takes Uri
as a parameter. Query String in URI section describes a fluent API for building URIs with query parameters.
Or more complicated ones, like this POST
:
- Scala
- Java
-
source
HttpRequest.POST("https://userservice.example/users") .withEntity(HttpEntities.create(ContentTypes.TEXT_PLAIN_UTF8, "data"));
See the API documentation of HttpRequest
for more information on how to customize your requests.
Processing responses
When you receive a response, you can use the Marshalling API to convert the response entity into an object: