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
5
5
**This mode is useful for development, but it is not recommended to use it in production. **
6
6
**More about Debug mode at the end of Examples section. **
7
7
8
- This is the minimal example of using the library.
8
+ This is the minimal example of using the library with CircuitPython .
9
9
This example is serving a simple static text message.
10
10
11
11
It also manually connects to the WiFi network.
@@ -43,6 +43,17 @@ Note that we still need to import ``socketpool`` and ``wifi`` modules.
43
43
:emphasize-lines: 11
44
44
:linenos:
45
45
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
+
46
57
Serving static files
47
58
--------------------
48
59
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