Last active
October 31, 2016 13:47
-
-
Save isaacabraham/22fb2f27838f699457ec to your computer and use it in GitHub Desktop.
F# Web API controller
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
type ExampleRequest = | |
{ Name : string | |
Age : int } | |
type ExampleController() = | |
inherit ApiController() | |
/// Maps to HTTP GET. | |
member __.Get(id : string) = | |
sprintf "Hello %s from F#!" id | |
/// Maps to HTTP POST. | |
member __.Post(request : ExampleRequest) = | |
async { | |
return match request.Age with | |
| 18 -> "You are 18!" | |
| _ -> "You are not 18!" | |
} |> Async.StartAsTask // can easily make asynchronous controller methods. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment