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
3. Run `magic install` at the root of your project, where `mojoproject.toml` is located
64
68
4. Lightbug should now be installed as a dependency. You can import all the default imports at once, e.g:
69
+
65
70
```mojo
66
71
from lightbug_http import *
67
72
```
73
+
68
74
or import individual structs and functions, e.g.
75
+
69
76
```mojo
70
77
from lightbug_http.service import HTTPService
71
78
from lightbug_http.http import HTTPRequest, HTTPResponse, OK, NotFound
72
79
```
80
+
73
81
there are some default handlers you can play with:
82
+
74
83
```mojo
75
84
from lightbug_http.service import Printer # prints request details to console
76
85
from lightbug_http.service import Welcome # serves an HTML file with an image (currently requires manually adding files to static folder, details below)
77
86
from lightbug_http.service import ExampleRouter # serves /, /first, /second, and /echo routes
78
87
```
88
+
79
89
5. Add your handler in `lightbug.🔥` by passing a struct that satisfies the following trait:
Pure Mojo-based client is available by default. This client is also used internally for testing the server.
217
234
218
235
## Switching between pure Mojo and Python implementations
236
+
219
237
By default, Lightbug uses the pure Mojo implementation for networking. To use Python's `socket` library instead, just import the `PythonServer` instead of the `Server` with the following line:
238
+
220
239
```mojo
221
240
from lightbug_http.python.server import PythonServer
222
241
```
242
+
223
243
You can then use all the regular server commands in the same way as with the default server.
224
244
Note: as of September, 2024, `PythonServer` and `PythonClient` throw a compilation error when starting. There's an open [issue](https://github.com/saviorand/lightbug_http/issues/41) to fix this - contributions welcome!
0 commit comments