Requests and Responses
Read input and return output.
Request as a Value
In http4s a Request[F] is an immutable value carrying the method, URI, headers, HTTP version, and a streaming body. You inspect it with pure accessors and never mutate it in place.
To change a request you produce a copy via withHeaders, withUri, or similar combinators.
val r: Request[IO] = Request[IO](
method = Method.GET,
uri = uri"/health"
)The Streaming Body
The body of a request or response is an fs2.Stream[F, Byte]. It is consumed lazily and effectfully, so large payloads never have to sit fully in memory.
You usually do not touch raw bytes; an EntityDecoder handles decoding for you.
// raw access (rarely needed)
val bytes: fs2.Stream[IO, Byte] = request.bodyAll lessons in this course
- Routes and HttpRoutes
- Requests and Responses
- JSON Endpoints
- Serving the Application