Utilize APIs from the HTTP module to send HTTP requests to a server and retrieve data.
import urequests
# GET request
req = urequests.request(
method='GET',
url='http://api.m5stack.com/v1',
headers={'Content-Type':'text/html'}
)
# POST request
req = urequests.request(
method='POST',
url='http://api.m5stack.com/v1',
json={'KEY':'VALUE'},
headers={'Content-Type':'text/html'}
)
# Get response status code
print(req.status_code)
# Get response Reason-Phrase
print(req.reason)
# Get raw response body
print(req.content)
# Get response body as string
print(req.text)
# Get response body as JSON
print(req.json)