Api
Documentation for Oxygen.jl
Starting the webserver
Oxygen.serve — Function
serve(; middleware::Vector=[], handler=stream_handler, host="127.0.0.1", port=8080, async=false, parallel=false, serialize=true, catch_errors=true, docs=true, metrics=true, mcp=true, mcp_path="/mcp", mcp_server_name="Oxygen", mcp_server_version=v"1.0.0", mcp_server_description=nothing, stdio=false, show_errors=true, show_banner=true, docs_path="/docs", schema_path="/schema", external_url=nothing, access_log=oxygen_logfmt, revise, kwargs...)Start the webserver with your own custom request handler
Oxygen.serveparallel — Function
serveparallel(; middleware::Vector=[], handler=stream_handler, host="127.0.0.1", port=8080, serialize=true, async=false, catch_errors=true, docs=true, metrics=true, kwargs...)Routing
Oxygen.@get — Macro
@get(path::String, func::Function)Used to register a function to a specific endpoint to handle GET requests
Oxygen.@post — Macro
@post(path::String, func::Function)Used to register a function to a specific endpoint to handle POST requests
Oxygen.@put — Macro
@put(path::String, func::Function)Used to register a function to a specific endpoint to handle PUT requests
Oxygen.@patch — Macro
@patch(path::String, func::Function)Used to register a function to a specific endpoint to handle PATCH requests
Oxygen.@delete — Macro
@delete(path::String, func::Function)Used to register a function to a specific endpoint to handle DELETE requests
Oxygen.@route — Macro
@route(methods::Array{String}, path::String, func::Function)Used to register a function to a specific endpoint to handle mulitiple request types
Oxygen.post — Method
post(func::Function, path::String)
post(func::Function, path::HOFRouter)Convenience function to register a POST route. Equivalent to @post.
Oxygen.put — Method
put(func::Function, path::String)
put(func::Function, path::HOFRouter)Convenience function to register a PUT route. Equivalent to @put.
Oxygen.patch — Method
patch(func::Function, path::String)
patch(func::Function, path::HOFRouter)Convenience function to register a PATCH route. Equivalent to @patch.
Oxygen.delete — Method
delete(func::Function, path::String)
delete(func::Function, path::HOFRouter)Convenience function to register a DELETE route. Equivalent to @delete.
Oxygen.route — Method
route(methods::Vector{String}, path::Union{String,HOFRouter}, func::Function)Register func to handle every HTTP method in methods at path. Equivalent to applying @route to the same arguments.
Mounting Files
Oxygen.@staticfiles — Macro
@staticfiles(folder::String, mountdir::String, headers::Vector{Pair{String,String}}=[])Mount all files inside the /static folder (or user defined mount point)
Oxygen.@dynamicfiles — Macro
@dynamicfiles(folder::String, mountdir::String, headers::Vector{Pair{String,String}}=[])Mount all files inside the /static folder (or user defined mount point), but files are re-read on each request
Oxygen.staticfiles — Function
staticfiles(folder::String, mountdir::String; headers::Vector{Pair{String,String}}=[], loadfile::Union{Function,Nothing}=nothing)Mount all files inside the /static folder (or user defined mount point). The headers array will get applied to all mounted files
Oxygen.dynamicfiles — Function
dynamicfiles(folder::String, mountdir::String; headers::Vector{Pair{String,String}}=[], loadfile::Union{Function,Nothing}=nothing)Mount all files inside the /static folder (or user defined mount point), but files are re-read on each request. The headers array will get applied to all mounted files
Autogenerated Docs
Oxygen.configdocs — Function
configdocs(docspath::String = "/docs", schemapath::String = "/schema")Configure the default docs and schema endpoints
Oxygen.enabledocs — Function
enabledocs()Deprecated. Documentation endpoints are enabled by default; use the docs keyword argument to serve instead.
Oxygen.disabledocs — Function
disabledocs()Deprecated. Use the docs keyword argument to serve instead.
Oxygen.isdocsenabled — Function
isdocsenabled()Deprecated. Returns true; use the docs keyword argument to serve instead.
Oxygen.mergeschema — Function
mergeschema(route::String, customschema::Dict)Merge the schema of a specific route
Oxygen.setschema — Function
setschema(customschema::Dict)Overwrites the entire internal schema
Oxygen.getschema — Function
getschema()Return the current internal schema for this app
Helper functions
Oxygen.Core.Util.queryparams — Function
Query parameter helpers, shadowing URIs.queryparamsOxygen.Core.RequestBody.formdata — Function
formdata(request::HTTP.Response)Read the html form data from the body of a HTTP.Response
formdata(request::HTTP.Request)Read the html form data from the body of a HTTP.Request
Oxygen.Core.Util.html — Function
html(content::String; status::Int, headers::Vector{Pair}) :: HTTP.ResponseA convenience function to return a String that should be interpreted as HTML
Oxygen.Core.RequestBody.text — Function
text(response::HTTP.Response)Read the body of a HTTP.Response as a String
text(content::String; status::Int, headers::Vector{Pair}) :: HTTP.ResponseA convenience function to return a String that should be interpreted as plain text
text(request::HTTP.Request)Read the body of a HTTP.Request as a String
Oxygen.Core.Util.file — Function
file(filepath::String; loadfile=nothing, status = 200, headers = []) :: HTTP.ResponseReads a file and returns a HTTP.Response. The file is read as binary. If the file does not exist, an ArgumentError is thrown. The MIME type and the size of the file are added to the headers.
Arguments
filepath: The path to the file to be read.loadfile: An optional function to load the file. If not provided, the file is read using theopenfunction.status: The HTTP status code to be used in the response. Defaults to 200.headers: Any additional headers to be included in the response. Defaults to an empty array.
Returns
- A HTTP response.
Oxygen.Core.Util.xml — Function
xml(content::String; status::Int, headers::Vector{Pair}) :: HTTP.ResponseA convenience function to return a String that should be interpreted as XML
Oxygen.Core.Util.js — Function
js(content::String; status::Int, headers::Vector{Pair}) :: HTTP.ResponseA convenience function to return a String that should be interpreted as JavaScript
Oxygen.Core.RequestBody.json — Function
json(response::HTTP.Response; keyword_arguments)Read the body of a HTTP.Response as JSON with additional keyword arguments
json(response::HTTP.Response, class_type; keyword_arguments)Read the body of a HTTP.Response as JSON with additional keyword arguments and serialize it into a custom struct
json(content::Any; status::Int, headers::Vector{Pair}) :: HTTP.ResponseA convenience function to return a String that should be interpreted as JSON
json(content::Vector{UInt8}; status::Int, headers::Vector{Pair}) :: HTTP.ResponseA helper function that can be passed binary data that should be interpreted as JSON. No conversion is done on the content since it's already in binary format.
json(request::HTTP.Request; keyword_arguments...)Read the body of a HTTP.Request as JSON with additional arguments for the read/serializer.
json(request::HTTP.Request, class_type; keyword_arguments...)Read the body of a HTTP.Request as JSON with additional arguments for the read/serializer into a custom struct.
Oxygen.Core.Util.css — Function
css(content::String; status::Int, headers::Vector{Pair}) :: HTTP.ResponseA convenience function to return a String that should be interpreted as CSS
Oxygen.Core.RequestBody.binary — Function
binary(content::Vector{UInt8}; status::Int, headers::Vector{Pair}) :: HTTP.ResponseA convenience function to return a Vector of UInt8 that should be interpreted as binary data
binary(request::HTTP.Request)Read the body of a HTTP.Request as a Vector{UInt8}
Repeat Tasks & Cron Scheduling
Oxygen.@cron — Macro
@cron(expression::String, func::Function)Registers a function with a cron expression. This will extract either the function name or the random Id julia assigns to each lambda function.
@cron(expression::String, name::String, func::Function)This variation provides way manually "name" a registered function. This information is used by the server on startup to log out all cron jobs.
Oxygen.starttasks — Function
starttasks()Start all background repeat tasks
Oxygen.stoptasks — Function
stoptasks()Stop all background repeat tasks
Oxygen.cleartasks — Function
cleartasks(ct::ServerContext)Clear any stored repeat task definitions
Oxygen.startcronjobs — Function
startcronjobs()Start all the cron cronjobs within their own async task. Each individual task will loop conintually and sleep untill the next time it's suppost to
Oxygen.stopcronjobs — Function
stopcronjobs()Stop each background task by toggling a global reference that all cron jobs reference
Oxygen.clearcronjobs — Function
Clears all cron job defintions
Extra's
Oxygen.router — Function
Oxygen.internalrequest — Function
internalrequest(req::HTTP.Request; middleware::Vector=[], serialize::Bool=true, catch_errors::Bool=true)Directly call one of our other endpoints registered with the router, using your own middleware and bypassing any globally defined middleware
Oxygen.Core.Util.redirect — Function
redirect(path::String; code = 307)return a redirect response
Oxygen.terminate — Function
terminate(ctx)Gracefully shuts down the webserver
Oxygen.resetstate — Function
resetstate()Reset all the internal state variables