From a1043bfa40fb1a4529c4a1acb90b8395e6a17a7c Mon Sep 17 00:00:00 2001 From: Matei Adriel Date: Thu, 2 Jan 2020 13:49:26 +0200 Subject: [PATCH] fsharp(todolist-api): feat: route for the todo by id thing Signed-off-by: prescientmoon --- fsharp/todolist-api/src/App.fs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/fsharp/todolist-api/src/App.fs b/fsharp/todolist-api/src/App.fs index f33e6b9..8c8aa56 100644 --- a/fsharp/todolist-api/src/App.fs +++ b/fsharp/todolist-api/src/App.fs @@ -2,10 +2,25 @@ open Suave open Suave.Successful +open Suave.Operators +open Suave.Filters +open Suave.RequestErrors + +module App = + let todoById (id) = + let todo = Db.Context.getContext() |> Db.Queries.getTodosById id + + match todo with + | Some inner -> OK <| sprintf "%A" inner.Name + | None -> id |> sprintf "Cannot find todo with id %i" |> NOT_FOUND + + let mainWebPart: WebPart = choose [ + GET >=> choose [ + pathScan "/todos/%i" todoById + ]] [] -let main argv = - - startWebServer defaultConfig (OK "hello world") +let main _ = + startWebServer defaultConfig App.mainWebPart 0 // return an integer exit code