I like the new System.Net.Http.HttpClient class. It has a nice simple API, it doesn't throw on normal errors. But its async only.
I need code that goes (deep inside a server)
foo();
bar();
// compute stuff
var x = GetThingFromOtherServerViaHttp();
// compute more stuff
wiz(x);
classic sequential synchronous code. I saw several SO question that were similar but never actually ended up saying 'do this'. I looked at
client.PostAsync.Wait()
the world screams 'dont do this'. How about:
client.PostAsync.Result()
isnt this just Wait in disguise?
In the end I ended up passing in a lambda callback that processed the result and then awoke the calling thread that was explicitly waiting on a EventWaitHandle. A lot of plumbing. Is there something a little simpler or shoul I just go back to using the old http clients
EDIT:After further reading I suspect that this code has the same issues as Wait and Result, its just a more longwinded deadlock
EDIT: I had MS PM confirm to me recently that there is a mandate 'any API that might take > X ms (I forgot X) must be async', many PMs interpret this as 'async only' (not clear if this is what is intended). Hence the Document DB api being only async.