Last active
December 20, 2017 12:01
-
-
Save allrameest/c6bfb3fc49aa2d9cc0496ccf3956f01d to your computer and use it in GitHub Desktop.
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
httpDelete = httpReq "DELETE" | |
httpPut = httpReq "PUT" | |
httpReq : String -> String -> Http.Body -> Decode.Decoder a -> Http.Request a | |
httpReq method url body decoder = | |
Http.request | |
{ method = method | |
, headers = [] | |
, url = url | |
, body = body | |
, expect = Http.expectJson decoder | |
, timeout = Nothing | |
, withCredentials = False | |
} | |
static async Task MainAsync() | |
{ | |
await HttpReq("GET")("http://www.example.com/")(null); | |
await HttpReq("POST")("http://www.lol.com/")("body"); | |
var httpDelete = HttpReq("DELETE"); | |
var httpPut = HttpReq("PUT"); | |
await httpDelete("http://www.foo.com/")(null); | |
await httpPut("http://www.foo.com/")("asdf"); | |
} | |
private static Func<string, Func<string, Task<string>>> HttpReq(string method) | |
{ | |
return Url; | |
Func<string, Task<string>> Url(string url) | |
{ | |
return Body; | |
Task<string> Body(string body) | |
{ | |
Console.WriteLine($"{method} {url}"); | |
if (body != null) Console.WriteLine($"Body: {body}"); | |
Console.WriteLine(); | |
return Task.FromResult("result from " + url); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment