-
-
Notifications
You must be signed in to change notification settings - Fork 32
Closed
Description
On the forums, I encountered some confusion about a @get route at the top level of a package module:
https://discourse.julialang.org/t/difference-between-include-and-using/87795
The problem with putting the routes at the top level of the module is that this is only invoked during precompilation. It is not invoked when the module is loaded.
For the routes to be loaded at module initialization, the routes should be declared from __init__ or some function called from __init__():
module OxygenExample
using Oxygen
using HTTP
function runserver()
serve()
end
function __init__()
@get "/greet" function(req::HTTP.Request)
return "hello world!"
end
# routes may also be contained in src/main.jl
include(joinpath(@__DIR__,"main.jl"))
end
end # module OxygenExampleMetadata
Metadata
Assignees
Labels
No labels