Implement a REST server in Julia?

Indeed, Oxygen.jl handels this case very well ! And the interface looks very lightweight and pleasant to use.

(for reference here is my test code: a call to e.g. /long/1 does not block a call to /short/1 )

# julia is started with
# julia -t4

using Oxygen, Dates, HTTP

function long(a)
    t = Dates.now() + Dates.Minute(1)

    while (t > Dates.now())
        a = a+1
    end
    return a
end

@get "/long/{a}" function(req::HTTP.Request,a::Int)
    @info "long"
    return Dict("value" => long(a))
end

@get "/short/{a}" function(req::HTTP.Request,a::Int)
    @info "short"
    return Dict("value" => a)
end

serveparallel()
6 Likes