You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9-6
Original file line number
Diff line number
Diff line change
@@ -28,14 +28,14 @@ Lightbug is a simple and sweet HTTP framework for Mojo that builds on best pract
28
28
This is not production ready yet. We're aiming to keep up with new developments in Mojo, but it might take some time to get to a point when this is safe to use in real-world applications.
29
29
30
30
Lightbug currently has the following features:
31
+
-[x] Pure Mojo networking! No dependencies on Python by default
31
32
-[x] Set up a server to listen on a given host/port
32
33
-[x] Assign your own custom handler to a route
33
34
-[x] Craft HTTP requests and responses with built-in primitives
34
35
-[x] Everything is fully typed, with no `def` functions used
35
36
36
37
37
38
We're working on support for the following (contributors welcome!):
38
-
-[ ] Pure Mojo networking (while most of the code is in Mojo, we call Python's `socket` library in several parts of the code)
39
39
-[ ] Better error handling, improved form/multipart and JSON support
40
40
-[ ] Multiple simultaneous connections, parallelization and performance optimizations
41
41
-[ ] WebSockets, HTTP 2.0
@@ -104,22 +104,25 @@ Once you have Mojo up and running on your local machine,
104
104
We plan to add routing in a future library called `lightbug_api`, see [Roadmap](#roadmap) for more details.
105
105
3. Run `mojo main.mojo`. This will start up a server listening on `localhost:8080`. Or, if you prefer to import the server into your own app:
106
106
```mojo
107
-
from lightbug_http.io.bytes import Bytes
108
-
from lightbug_http.python.server import PythonServer
107
+
from lightbug_http.sys.server import SysServer
109
108
from lightbug_http.service import Printer
110
109
111
110
112
111
fn main() raises:
113
-
var server = PythonServer()
112
+
var server = SysServer()
114
113
let handler = Printer()
115
114
server.listen_and_serve("0.0.0.0:8080", handler)
116
115
```
117
-
118
116
Feel free to change the settings in `listen_and_serve()` to serve on a particular host and port.
119
117
120
118
<palign="right">(<ahref="#readme-top">back to top</a>)</p>
121
119
122
-
120
+
## Switching between pure Mojo and Python implementations
121
+
By default, Lightbug uses the pure Mojo implementation for networking. To use Python's `socket` library instead, just import the `PythonServer` instead of the `SysServer` with the following line:
122
+
```mojo
123
+
from lightbug_http.python.server import PythonServer
124
+
```
125
+
You can then use all the regular server commands in the same way as with the default server.
0 commit comments