-
-
Save tomatophobia/e07003a0416b8d51bf32ee306c711a81 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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