Intro

The following code snippet gets at the essence of the framework

using Bonsai, HTTP

const app = App()

function index(stream::HTTP.Stream)
    query = Bonsai.read( stream, Query(name=Union{String, Nothing}))
    name = isnothing(query.name) ? "John Doe" : query.name  
    Bonsai.write(stream, Body("Hi, $name"))
end

function register_handlers!(app)
    app.get["/"] = index
end

function run()
    register_handlers!(app)
    start(app, port=9091)
end

run()

The package provides abstraction so we use the HTTP.Stream IO type to declaratively read and write data by specifying our inputs and outputs as types. Calls to Bonsai.read will extract data from the HTTP Request and likewise those to Bonsai.write will construct an HTTP response.

Features

Some features include:

  • Live Reloading (using Revise)
  • WebSockets
  • Tight integration with StructTypes
  • Flexible Middleware
  • Automatic OpenAPI Generetation using JET

For a more detailed breakdown read the handlers section or if you prefer to dive in check out the examples.

About

Bonsai aims to be minimalistic and not impose a specific structure on the developer, the API is inspired by FastAPI, Fibre and Express.