1
Fork 0

fsharp(todolist-api): feat: route for the todo by id thing

Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
Matei Adriel 2020-01-02 13:49:26 +02:00 committed by prescientmoon
parent 3e1615f0a2
commit a1043bfa40
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4

View file

@ -2,10 +2,25 @@
open Suave open Suave
open Suave.Successful 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
]]
[<EntryPoint>] [<EntryPoint>]
let main argv = let main _ =
startWebServer defaultConfig App.mainWebPart
startWebServer defaultConfig (OK "hello world")
0 // return an integer exit code 0 // return an integer exit code