fsharp(todolist-api): feat: route for the todo by id thing
Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
parent
3e1615f0a2
commit
a1043bfa40
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue