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