Test Pyscript

PyScript - HTTP Requests pyfetch

This webpage fetches a cat fact from cat-facts and displays below request status and response text.

It uses pyfetch wrapper from pyodide in order to have an async request. Remember to import asyncio and await for the response...we are in asyincland in the browser!

Overall, I believe Pyscript is very cool! :-)

from pyodide.http import pyfetch import asyncio response = await pyfetch(url="http://127.0.0.1:5000/api/get_product", method="GET") print(response) variable = response response_dict = await response.json() status = f"Request status: {response.status}" text = f"Text: {response_dict['product_name']}" pyscript.write('request_status', status) pyscript.write('request_text', text)