When using Oxygen.jl, I noticed an unexpected difference between using and include. I created a simple project using a slightly modified version of the example code in the readme.
module OxygenExample
using Oxygen
using HTTP
@get "/greet" function(req::HTTP.Request)
return "hello world!"
end
function runserver()
serve()
end
end # module OxygenExample
This doesn’t work, when I fetch /greet, I always get a 404:
When you use add you are adding a snapshot of the package at the time you did that. The alternative is to use dev which will load whatever is currently located there.
You should generally not use include outside of a package module. You lose most of the benefits of a package such as precompilation caching.
If you have an existing environment in the folder --project seems to do the same thing as --project=. for me at least. Though if there isn’t any it activates the default. So in this case it seems like there should definitely be an environment so I don’t think that would be the reason.
With that said I get the same results as OP, not really sure why this is happening.
I misunderstood the problem, but I see what the issue is now.
In your example above, you invoked @get at the top level of the module OxygenExample. The problem is that this is only executed during precompilation. It is not executed when loading the module via using OxygenExample.
To have it execute when loading the module, move the code into __init__:
module OxygenExample
using Oxygen
using HTTP
function __init__()
@get "/greet" function(req::HTTP.Request)
return "hello world!"
end
end
function runserver()
serve()
end
end # module OxygenExample