Discuss Scratch

MyScratchedAccount
Scratcher
1000+ posts

How does the scratch API work?

I am wondering how the scratch API works I might use it
Just wondering!
ajskateboarder
Scratcher
1000+ posts

How does the scratch API work?

To begin, an API is an Application Programming Interface which, in Scratch's case, follows a simple client-server model where the Scratch website - the client - requests data from any of Scratch's APIs (assets, projects, api) to display to the user.

Scratch's API is actually very simple:



(made with Excalidraw btw)

There are actually multiple APIs Scratch has:

Last edited by ajskateboarder (Jan. 17, 2023 12:52:01)

ScratchCatHELLO
Scratcher
1000+ posts

How does the scratch API work?

it works like all websites do. you ask the server to give you a page and give it some extra details and it sends it back to you. when you open scratch in your browser, that's what happens. the difference is that browsers do all the requesting for you. when you program using an API, you have to handle it yourself.

in python, the de facto way to do this is with the requests library. for example, do:
import requests
response = requests.get("link") # you may also include headers
if response.status_code = 200:
    print(response.json()) # .json() produces a dictionary
else:
    print(f"request failed, error code: {response.status_code}")
OPGalaxyCoder
Scratcher
2 posts

How does the scratch API work?

But how do you get the weather using the scratch api

Powered by DjangoBB