Closed jrrickerson closed 1 year ago
I'm going to try working on this one at PyCon US 2023 sprints
I am not entirely sure what you mean, but there is already a very simple example: https://github.com/adafruit/Adafruit_CircuitPython_HTTPServer/blob/main/examples/httpserver_simple_serve.py
If you delete all docstrings, prints etc. it is only 4-5 lines long, not considering connecting to WiFi. If you want it without a handler for "/", it is 2 lines long.
One could for sure save some characters but this would not be a realistic scenario for using this lib. Correct me if I understood this Issue incorrectly.
The minified version of the example would be something like this:
import os, socketpool, wifi
from adafruit_httpserver.server import HTTPServer
ssid, password = os.getenv("WIFI_SSID"), os.getenv("WIFI_PASSWORD")
wifi.radio.connect(ssid, password)
HTTPServer(socketpool.SocketPool(wifi.radio), "/").serve_forever(str(wifi.radio.ipv4_address))
I believe it should be possible to omit manually connecting to WiFi by using special env vars, making the example even shorter:
import socketpool, wifi
from adafruit_httpserver.server import HTTPServer
HTTPServer(socketpool.SocketPool(wifi.radio), "/").serve_forever(str(wifi.radio.ipv4_address))
but at this stage it kind of misses the point of being an example.
I did see the simple server example, but I thought I could provide another that required a bit less work by the end user, and fit the library standard of having a "
Kinda going for less setup steps rather than less lines of code, if that makes sense
Ok, I see. To be honest I believe it would make more sense to modify existing one, and replace response.send_file("index.html")
with response.send("Hello World")
.
Creating a separate example with only one line modified seems like a overkill for me.
@michalpokusa Thanks, I appreciate the feedback. I can make adjustments to the PR to merge the two examples then.
@michalpokusa I've merged the two examples, and renamed the "simple_serve" example to "simpletest" to adhere to the convention which appears to be in the other CircuitPython libraries and this contributing guide: https://circuitpython.org/contributing/library-infrastructure-issues
Please let me know if you see any other areas for improvement.
Create a bare minimum example that proves the HTTPServer is running on the device, akin to a "Hello World"