Forum

HTTP get a page?

Is there a library for http? I’m not seeing it, I would like to do this …

var client = new HttpClient();
var string = client.GetAsync("http://google.com");

I tried adding a reference to System.Net.Http and I can see the Create on HttpClient but I can’t get much further.
Thanks
–Andy

I think what you’re looking for is stored away in the Experimental Aspect of the Node Browser:
image

This gets you HTTPGet/Post … it doesn’t use HttpClient though, but you can check its implementation.

image

Thanks, I had that off, it works great!

In general, if I did want to work with HttpClient, would I need to wrap it in my own library?
I couldn’t see how to work the instance once I had one here …

This is the other end, but there are some patch examples that should give you and idea on how to wrap an instance of a class in a user friendly node:

Ahh, thanks, I need to start inspecting these implementations to see how things work.

It works, but I don’t make use of the async part here much (I experimented with ContinueWith, but failed, it was still blocking):

Seems you need a task and I would say cache result of task, but who cares cache a task ;)

Codewise, if you do that in code you will block, you need to do that inside of task and await task to get it unblocking

GetAsync is already async - so is ReadAsStringAsync.
I explicitly tried to bind them closely together with things I found in the Task Category (ContinueWith) instead of making use of the AsyncTask region, which I deliberately tried not to do because it didn’t seem right here.
I felt like there had to be a way to spawn the next Task in a more elegant way.

That would be a insync call
var string = await client.GetAsync(bla bla)
Would not block, and would be an async call, so if you don’t want to block thread you have to await the result

Not sure 100% how it works in VL, but in c# it would work that way…
Here check that one out https://channel9.msdn.com/Shows/On-NET/Supporting-IAsyncEnumerable-with-LINQ?term=Async%209&pubDate=year&lang-en=true

I’m still trying to get my head around how I should be thinking about vvvv.
I’m a .NET guy, so I keep thinking about starting with my .NET code and then re-writing that as nodes. Really, I should be thinking one level up, I think, piecing together blocks. But I guess you have to make those blocks first, which I would almost rather do this async code in a class library and then pull that into vvvv.

@andywestion When dealing with tasks we often wrap them in observables, as we have better support for those library wise. Patching with tasks is coming up more frequently, see also the quest here https://github.com/vvvv/VL-Language/issues/25

And yes there’s nothing wrong with writing your “blocks” in C# and piecing them together in VL.