Http get-request directly from Grasshopper

Hello, quick question:
Is it possible to load external Json data with a get request in a python/c# component, or is that not allowed in shapediver?
To be more precise: I want to acces a public database with a http-request.
The user will input a search as text and the request is made. If the request was successful, the geometry will be generated from the json data (coordinates) and displayed in the shapediver viewer.
Thanks

You don’t need Python for that, Javascript has been doing it for a very long time.
(“AJAX” - Asynchronous JavaScript And XML.)

https://api.jquery.com/jquery.ajax/

https://www.w3schools.com/js/js_ajax_intro.asp

Hey Joseph, thanks for the answer, however I was asking specifically about how I would implement this in a grasshopper definition inside of the shapediver plugin, without having to go through the shapediver API.

Yeah, sorry, I realized after I posted that I was stating the obvious.

1 Like

This is not possible in ShapeDiver because any scripts with HTTP requests are blocked. You need to deal with the access to the public database outside Grasshopper in the JavaScript code. You can then process the JSON file with ShapeDiver JSON components. See more on how to work with JSON in this video tutorial

3 Likes

Thank you for your answer. I was already guessing it would be that way… I will have to learn some more Javascript and interface with the api.

Maybe my first reply will be useful after all? jQuery!

As much as I would love to do exactly what you mention as well, I think one issue is, that Grasshopper is not really designed for this asynchronous kind of working. So even if you had a node to get from an API, it would mean recalculating the whole Grasshopper script at least twice. Grasshopper is not really designed as a way to connect different modules that calculate separately, even though you can of course have some switches and gates, but it gets clunky very quickly.