Last active
December 11, 2015 17:38
-
-
Save YusukeKokubo/4635710 to your computer and use it in GitHub Desktop.
hello lemon (todo)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Server | |
open Lemon | |
open System.Collections.Generic | |
let todolist = ResizeArray<string>() | |
let (|Int|_|) (str: string) = | |
match System.Int32.TryParse(str) with | |
| true, x -> Some x | |
| _ -> None | |
let (server:Server) = function | |
| GET(Url []) -> | |
let res = Seq.mapi (fun i todo -> i.ToString() + ":" + todo) todolist | |
ok >> response (String.concat "\n" res) | |
| GET(Url ["add"; todo]) -> | |
todolist.Add(todo) | |
ok >> response ("added " + todo) | |
| GET(Url [Int id; "edit"; todo]) -> | |
let before = todolist.[id] | |
todolist.[id] <- todo | |
ok >> response ("updated " + id.ToString() + ":" + before + " -> " + todo) | |
| GET(Url [Int id; "delete"]) -> | |
todolist.RemoveAt(id) | |
ok >> response ("deleted " + id.ToString()) | |
| _ -> notFound |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment