Created
August 15, 2017 15:02
-
-
Save vshapenko/1a973fa82fcd86592cfcc14550c237e9 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
type RequestBuilder()= | |
member this.Combine (a,b) = a>>b | |
member this.Yield (())=fun r->r | |
member this.Yield (f)=f | |
member this.Delay(f)=f() | |
[<CustomOperation("method")>] | |
member this.Method(f:HttpRequestMessage->HttpRequestMessage,m:HttpMethod)= | |
f>>fun r-> | |
r.Method<-m | |
r | |
[<CustomOperation("header")>] | |
member this.Header(f:HttpRequestMessage->HttpRequestMessage,name:string,value:string)= | |
f>>fun r-> | |
r.Headers.Add(name,value) | |
r | |
[<CustomOperation("url")>] | |
member this.Url (f:HttpRequestMessage->HttpRequestMessage,uri:string)= | |
f>>fun r-> | |
r.RequestUri<-new Uri(uri) | |
r | |
[<CustomOperation("custom")>] | |
member this.Custom (f:HttpRequestMessage->HttpRequestMessage,apply:HttpRequestMessage->HttpRequestMessage)= | |
f>>fun r-> | |
apply r | |
[<CustomOperation("param")>] | |
member this.Parameter (f:HttpRequestMessage->HttpRequestMessage,name:string,value:string)= | |
f>>fun r-> | |
let builder=new UriBuilder(r.RequestUri) | |
let query=HttpUtility.ParseQueryString(builder.Query) | |
query.[name]<-value | |
builder.Query<-query.ToString() | |
r.RequestUri<-builder.Uri | |
r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment