Lightbug API is a framework that allows to quickly write expressive APIs.
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.
Lightbug API currently has the following features:
- Assign handlers on given routes with different methods (GET, POST, ...)
- Logging - @toasty/stump
- CLI and Terminal - @toasty/prism, @toasty/mog
- Date/Time - @mojoto/morrow and @toasty/small-time
Learn how to get up and running with Mojo on the Modular website. Once you have a Mojo project set up locally,
- Add the
mojo-community
channel to yourmojoproject.toml
, e.g:[project] channels = ["conda-forge", "https://conda.modular.com/max", "https://repo.prefix.dev/mojo-community"]
- Add
lightbug_api
andlightbug_http
in dependencies:[dependencies] lightbug_api = ">=0.1.0.dev2024092905" lightbug_http = ">=0.1.4"
- Run
magic install
at the root of your project, wheremojoproject.toml
is located - Lightbug API should now be installed. You can import all the default imports at once, e.g:
or import individual structs and functions, e.g.
from lightbug_api import *
from lightbug_api.routing import Router
- Create one or more handlers for your routes that satiisfy the
HTTPService
trait:For example, to make atrait HTTPService: fn func(self, req: HTTPRequest) raises -> HTTPResponse: ...
Printer
service that prints some details about the request to console:from lightbug_http import HTTPRequest, HTTPResponse, OK @always_inline fn printer(req: HTTPRequest) -> HTTPResponse: print("Got a request on ", req.uri.path, " with method ", req.method) return OK(req.body_raw)
- Assign your handlers to routes and launch your app with
start_server()
:from lightbug_api import App from lightbug_http import HTTPRequest, HTTPResponse, OK @always_inline fn printer(req: HTTPRequest) -> HTTPResponse: print("Got a request on ", req.uri.path, " with method ", req.method) return OK(req.body_raw) @always_inline fn hello(req: HTTPRequest) -> HTTPResponse: return OK("Hello 🔥!") fn main() raises: var app = App() app.get("/", hello) app.post("/", printer) app.start_server()
- Excellent 😈. Your app is now listening on the selected port. You've got yourself a pure-Mojo API! 🔥
Want your name to show up here? See CONTRIBUTING.md!
Made with contrib.rocks.