Skip to content

About

Web requests in vanilla Scratch 3.0

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

39 Commits

Folders and files

Repository files navigation

ScratchWeb

HTTP GET requests in vanilla Scratch 3.0

How can I do this?

  • Create a certificate. Name it server.crt with the key file named server.key.
  • Install the requirements.txt dependencies
  • Simply add 127.0.0.1 translate-service.scratch.mit.edu to your hosts file (on windows - untested on linux Linux works too - untested on macOS)
  • Run server.py
  • Add a security exception for translate-service.scratch.mit.edu in your browser; the certificate is self-signed, and therefore, insecure

How is this possible?

translate

When the translate feature is used in scratch, It sends an HTTP GET request to "translate-service.scratch.mit.edu". inspect

Route the "translate-service.scratch.mit.edu" to localhost in the hosts file. hosts-file

Create a custom script to take the parameters that Scratch sends and use the string parameter as the url to return the content of. script

Improvements

Text Format

Input Format

https://example.com|body
         ^^          ^^
         URL        Body
               If applicable;
                 Leave empty
                 if not used
                (Keep the |)

Output Format

200|filetype|body <- Body
 ^     ^^<< Filetype
Status code h = Html
            c = Css
            t = plainText
            i = Image (base64 encoded)
            d = Data (lowercase hex encoded)
            n = http (Network) header
            j = Json

Request Methods

Change the target language to select the request method:

Language Request Uses Body?
Amharic GET No
Arabic POST Yes
Azerbaijani PUT Yes
Basque DELETE No
Bulgarian PATCH Yes
Catalan OPTIONS No
  • The response body of an OPTIONS request is replaced with the Allow header of the request.

Audio

Audio is not natively supported anymore. Please use something like this to play audio.

Images

ScratchWeb can convert image files to a Scratch-friendly base64 format. See image-client.sb3 for an example.

WebSockets

ScratchWeb now supports WebSockets!

  • URL must start with ws or wss
  • Language is irrelevant
  • The body will be sent to the WS server, the response will be received
  • Status code is hardcoded to 200, filetype to t

About

Web requests in vanilla Scratch 3.0

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages