Replies: 3 comments 27 replies
-
I like this idea - it may be worth looking at Pyodide's pyfetch function in their FFI for inspiration - or at least, maybe we put in the docs that this is different from pyfetch to minimize confusion. |
Beta Was this translation helpful? Give feedback.
-
To be honest we already have that: import json
from pyscript import window
response = await window.fetch(
"https://example.com",
method="GET",
headers={
"Content-Type": "application/json",
"Authorization": "Bearer some_token_123",
},
body=json.dumps({
"foo": "bar",
})
) From a worker this would/should work out of the box, from the main thread this would require awkward dictionary to object literal conversion ... I think it is indeed probably better to actually expose a fetch that automatically does such conversion without needing to pass through the |
Beta Was this translation helpful? Give feedback.
-
this is in with our best API yet |
Beta Was this translation helpful? Give feedback.
-
A common task in the browser is to fetch resources from the web. JavaScript has the
fetch
function to do this. We should provide a wrapper for this capability that works with both MicroPython and Pyodide.We should probably also do the same for
WebSocket
objects too.I imagine code that looks something like (rough draft, subject to refinement):
Beta Was this translation helpful? Give feedback.
All reactions