Questions about APIs and JS in Snap

So, I know that using JS functions in Snap is critisied, but I want to know; am I allowed to use GET calls to an API inside of a JS function or does that violate the terms of usage on Snap!?

Basically, I am trying to get data from a wikipedia article and print it onto the Snap stage, and I am wondering if there could be another way to approach this other than using JS functions, perchance?

You could use the URL block to get the contents of a webpage. You’d probably need to use a CORS proxy, though.

No JS required!

If you’re making anything other that GET calls, you should use the HTTP library.

How do I use a CORS proxy in Snap? I heard you talk about All Origins
Also what HTTP library?

JavaScript is there to use when the built-in or library blocks won't achieve your required results.

There is no restriction on what you do (except trying to access Snap!'s own cloud infrastructure)

What is critisced, is trying to just use Snap! as a wrapper around JavaScript and asking endless questions about how to do so :slight_smile:

Yeah I am not trying to access SnapCloud, jens is really salty about that. Just trying to GET content from a Wikipedia artical and print it to snap

Ok I did this inside of a url block:

Gives me JSON or something instead of pure HTML, how do I change that or does it not need to be changed

If you decode the json and then start drilling down into the data , you may start to get the droid you are looking for


I'd rather use "raw" so I can get HTML contents.

Carry on then :slight_smile:

That would be how to get raw HTML contents, then.

I’m currently out and about. I’ll provide more information when I can (so hopefully within an hour).

@cymplecy how do i view contents of the json when i split it?

Did you try using the blocks I posted?

But regardless, if you just want raw HTML - follow pajamaclaws21 advice

As an aside, many people in the past, have wanted to use Snap! to display web pages that are easily viewed by just typing a url into a browser

This has generally been considered a complete waste of time and energy :slight_smile:

But maybe you are not trying to do this?

I want to pick the TEXT data out of a wikipedia artical and write it using the pen "write ()" block on my stage

Web pages (like wikipedia articles) are complex data structures and are tricky to decode into the text that you, as a human reading the page in a browser, would consider to be the "TEXT" data

Why are you trying to do this in Snap! rather than just reading the web page in a browser?

For fun to be honest, and it is a learning experience. And I am pretty sure Snap! is about learning

Salty is an understatement

@cymplecy’s right. You’d probably be better off using the Wikipedia API + the HTTP library. I don’t have a screenshot of the HTTP library right now- do y’all have any??

The library is called "Web access services".

You can use GET directly on the Wikipedia API. Visit MediaWiki API help - Wikipedia to learn more. Note that it is already HTTPS.

For example this URL will report a great deal about Ukraine from Wikipedia:*&generator=prefixsearch&gpssearch=ukraine

And then you can use the split block with JSON format to parse the result