Experimenting with a web stack in Julia
Julia
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
views
Jolt.jl
JoltJson.jl
JoltView.jl
REQUIRE
RouteParser.jl
program.jl
readme.md
test.jl

readme.md

Jolt

An experimental sinatra style web framework for Julia

Example

using HttpServer
using Jolt
using JoltView

app = jolt()

app.get("/") do req, res, ctx
    "hello world"
end

app.get("/hello/:name") do req, res, ctx
    name = ctx.params[:name]
    "hello $name"
end

http = HttpHandler(app.dispatch) 
server = Server(http)
run(server, 8080)

Middleware

Middleware is achieved with a producer (co-routines)

app.use() do req, res, ctx
    url = req.resource

    println("start $url")

    produce()

    println("end $url")
end

Views

Views are currently implemented in a Mustache template like this:

<html>
    <body>
        Hello {{Name}}
    </body>
</html>

Your controller then just returns a View object and the data to render:

app.get("/view/:name") do req, res, ctx
    View("test", {"Name" => ctx.params[:name]})
end

JSON

Return a JSON response:

app.get("/json/:foo") do req, res, ctx
    x = Dict{String,Any}()
    x["foo"] = ctx.params[:foo]
    Json(x)
end

License

MIT