User Manual

HTTP GET with Requests
The code makes a HTTP GET request to Adafruit's WiFi testing website
- http://wifitest.adafruit.com/testwifi/index.html (https://adafru.it/FpZ).
To do this, we'll pass the URL into requests.get() . We're also going to save the response
from
the server into a
variable named response .
While we requested data from the server, we'd what the server responded with. Since we already saved the
server's response , we can read it back. Luckily for us, requests automatically decodes the server's response into
human-readable text, you can read it back by calling response.text .
Lastly, we'll perform a bit of cleanup by calling response.close() . This closes, deletes, and collect's the response's
data.
While some servers respond with text, some respond with json-formatted data consisting of attribute–value pairs.
CircuitPython_Requests can convert a JSON-formatted response from a server into a CPython dict. object.
We can also fetch and parse json data. We'll send a HTTP get to a url we know returns a json-formatted response
(instead of text data).
Then, the code calls response.json() to convert the response to a CPython dict .
HTTP POST with Requests
Requests can also POST data to a server by calling the requests.post method, passing it a data value.
esp32_cs = DigitalInOut(board.D9)
esp32_ready = DigitalInOut(board.D10)
esp32_reset = DigitalInOut(board.D5)
print("Fetching text from %s"%TEXT_URL)
response = requests.get(TEXT_URL)
print('-'*40)
print("Text Response: ", response.text)
print('-'*40)
response.close()
print("Fetching JSON data from %s"%JSON_GET_URL)
response = requests.get(JSON_GET_URL)
print('-'*40)
print("JSON Response: ", response.json())
print('-'*40)
response.close()
© Adafruit Industries
https://learn.adafruit.com/adafruit-airlift-featherwing-esp32-wifi-co-
processor-featherwing
Page 23 of 39