From 3daff97b1b8aae23bef743a0cdae08cbfc3f7fd9 Mon Sep 17 00:00:00 2001 From: noelwelsh Date: Sun, 21 Jan 2024 21:26:01 +0000 Subject: [PATCH] deploy: 215c71c3184dde8c625d03d6ace644f0c84a74dd --- routes/index.html | 2 +- routes/response.html | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/routes/index.html b/routes/index.html index ae7790c..969acc6 100644 --- a/routes/index.html +++ b/routes/index.html @@ -73,7 +73,7 @@

Constructing A Route

Type Transformations for Handlers

If you dig into the types produced by Requests, you notice a lot of tuple types are used. Here's an example, showing a Request producing a Tuple2.

val request = Request.get(Path.root / Param.int / Param.string)
-// request: Request[*:[Int, *:[String, EmptyTuple]], Unit, Unit, Unit] = krop.route.Request@11ab9062
+// request: Request[*:[Int, *:[String, EmptyTuple]], Unit, Unit, Unit] = krop.route.Request@3e606b49

However, when you come to use a handler with such a request, you can use a normal function with two arguments not a function that accepts a single Tuple2.

Route(request, Response.ok(Entity.text))
   .handle((int, string) => s"${int.toString}: ${string}")
diff --git a/routes/response.html b/routes/response.html index ff7d450..e12948d 100644 --- a/routes/response.html +++ b/routes/response.html @@ -40,8 +40,9 @@

Response

-

A Response describes how an HTTP response can be constructed from Scala values.

+

A Response describes how a HTTP response can be constructed from Scala values. A response can be anything that implements the Response trait, but the usual way to call one of the constructors on the Response companion object. For example

val response = Response.ok(Entity.html)
+

constructs a Response that responds with an HTTP OK, and an HTML entity constructed from a Scala String.