September 2023
Intermediate to advanced
470 pages
11h 12m
English
Now we can throw away the spike code and start to write the real main function. Since we decided that a list is owned by a user, it makes sense to encode this relationship inside the URL of our application to make it more user friendly, for example, like this:
| | http://localhost:8080/todo/user/listname |
Once we start the application—from the command line or from the IDE—calling this URL will show the to-do list named “listname” of the user “user.”
Let’s put this route into our main function as we did previously with the spike:
| | fun main() { |
| | val app: HttpHandler = routes( |
| ① | "/todo/{user}/{list}" bind Method.GET to ::showList |
| | ) |
| | app.asServer(Jetty(8080)).start() |
| | } |
| | |
| ② | fun showList(req: Request): Response { ... |
Read now
Unlock full access