Skip to content

Instantly share code, notes, and snippets.

@tomatophobia
Last active May 26, 2021 14:56
Show Gist options
  • Save tomatophobia/e07003a0416b8d51bf32ee306c711a81 to your computer and use it in GitHub Desktop.
Save tomatophobia/e07003a0416b8d51bf32ee306c711a81 to your computer and use it in GitHub Desktop.
case class Request(
method: Method,
uri: Uri,
// headers,
// httpVersion,
body: String = "",
)
case class Response(
status: Status,
// headers,
// httpVersion,
body: String = "",
)
type HttpApp = Request => Response
val helloWorld: HttpApp = {
case Request(POST, Uri("/hello"), name) =>
Response(OK, s"Hello, $name!")
case _ =>
Response(NotFound)
}
// Unit test
val req = Request(POST, Uri("/hello"), "Boston")
// req: Request = Request(POST,Uri(/hello),Boston)
assert("Hello, Boston!", helloWorld(req).body)
// ✔ Hello, Boston!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment