Configuring the HttpClient
Nomi does not create or configure the client. This page covers the three things the application sets up on it, and what happens when one is missing.
val client = HttpClient {
install(ContentNegotiation) {
json(SharedJson)
}
defaultRequest {
url("https://api.example.com/")
contentType(ContentType.Application.Json)
}
}
-
ContentNegotiation, matching the server’s format. Without it a request with a body fails while being prepared, and a response body fails to be read. -
A base URL, in
defaultRequest, ending in a slash if it carries a path. This is ordinary URL resolution:https://api.example.com/v1treatsv1as a resource to be replaced, silently dropping it, whereashttps://api.example.com/v1/keeps it. -
A
Content-Type, indefaultRequest.ContentNegotiationpicks its converter from the request’s content type; without one, everypost,putandpatchfails before reaching the network.
Mistakes
Get any of this wrong and a call throws rather than returning a CallStatus.
A misconfigured client is a programming error, not a call outcome.
| Mistake | What is raised |
|---|---|
No |
|
No |
|