File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ Simple Test
55**This mode is useful for development, but it is not recommended to use it in production. **
66**More about Debug mode at the end of Examples section. **
77
8- This is the minimal example of using the library.
8+ This is the minimal example of using the library with CircuitPython .
99This example is serving a simple static text message.
1010
1111It also manually connects to the WiFi network.
@@ -43,6 +43,17 @@ Note that we still need to import ``socketpool`` and ``wifi`` modules.
4343 :emphasize-lines: 11
4444 :linenos:
4545
46+ CPython usage
47+ --------------------
48+
49+ Library can also be used in CPython, no changes other than changing the ``socket_source `` are necessary.
50+
51+ .. literalinclude :: ../examples/httpserver_cpython.py
52+ :caption: examples/httpserver_cpython.py
53+ :emphasize-lines: 5,10
54+ :linenos:
55+
56+
4657Serving static files
4758--------------------
4859
Original file line number Diff line number Diff line change 1+ # SPDX-FileCopyrightText: 2024 Michał Pokusa
2+ #
3+ # SPDX-License-Identifier: Unlicense
4+
5+ import socket
6+
7+ from adafruit_httpserver import Server , Request , Response
8+
9+
10+ pool = socket
11+ server = Server (pool , "/static" , debug = True )
12+
13+
14+ @server .route ("/" )
15+ def base (request : Request ):
16+ """
17+ Serve a default static plain text message.
18+ """
19+ return Response (request , "Hello from the CircuitPython HTTP Server!" )
20+
21+
22+ server .serve_forever ("0.0.0.0" )
You can’t perform that action at this time.
0 commit comments