Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Lightbug-HQ/lightbug_api

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

33 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 


Logo

Lightbug API

๐Ÿ Author APIs in Pure Mojo ๐Ÿ”ฅ

Written in Mojo MIT License Contributors Welcome Join our Discord

Overview

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, ...)

Check Out These Mojo Libraries:

(back to top)

Getting Started

Learn how to get up and running with Mojo on the Modular website. Once you have a Mojo project set up locally,

  1. Add the mojo-community channel to your mojoproject.toml, e.g:
    [project]
    channels = ["conda-forge", "https://conda.modular.com/max", "https://repo.prefix.dev/mojo-community"]
  2. Add lightbug_api and lightbug_http in dependencies:
    [dependencies]
    lightbug_api = ">=0.1.0.dev2024092905"
    lightbug_http = ">=0.1.4"
  3. Run magic install at the root of your project, where mojoproject.toml is located
  4. Lightbug API should now be installed. You can import all the default imports at once, e.g:
    from lightbug_api import *
    or import individual structs and functions, e.g.
    from lightbug_api.routing import Router
  5. Create one or more handlers for your routes that satiisfy the HTTPService trait:
    trait HTTPService:
     fn func(self, req: HTTPRequest) raises -> HTTPResponse:
         ...
    For example, to make a 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)
  6. 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()
  7. Excellent ๐Ÿ˜ˆ. Your app is now listening on the selected port. You've got yourself a pure-Mojo API! ๐Ÿ”ฅ

Contributors

Want your name to show up here? See CONTRIBUTING.md!

Made with contrib.rocks.

About

Author APIs in pure Mojo! ๐Ÿ”ฅ๐Ÿ

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  
Morty Proxy This is a proxified and sanitized view of the page, visit original site.