Api

Documentation for Oxygen.jl

Starting the webserver

Oxygen.serveFunction
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, show_errors=true, show_banner=true, docs_path="/docs", schema_path="/schema", external_url=nothing, kwargs...)

Start the webserver with your own custom request handler

source
Oxygen.serveparallelFunction
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...)
source

Routing

Oxygen.@getMacro
@get(path::String, func::Function)

Used to register a function to a specific endpoint to handle GET requests

source
Oxygen.@postMacro
@post(path::String, func::Function)

Used to register a function to a specific endpoint to handle POST requests

source
Oxygen.@putMacro
@put(path::String, func::Function)

Used to register a function to a specific endpoint to handle PUT requests

source
Oxygen.@patchMacro
@patch(path::String, func::Function)

Used to register a function to a specific endpoint to handle PATCH requests

source
Oxygen.@deleteMacro
@delete(path::String, func::Function)

Used to register a function to a specific endpoint to handle DELETE requests

source
Oxygen.@routeMacro
@route(methods::Array{String}, path::String, func::Function)

Used to register a function to a specific endpoint to handle mulitiple request types

source
Missing docstring.

Missing docstring for get(path, func). Check Documenter's build log for details.

Missing docstring.

Missing docstring for post(path, func). Check Documenter's build log for details.

Missing docstring.

Missing docstring for put(path, func). Check Documenter's build log for details.

Missing docstring.

Missing docstring for patch(path, func). Check Documenter's build log for details.

Missing docstring.

Missing docstring for delete(path, func). Check Documenter's build log for details.

Missing docstring.

Missing docstring for route(methods, path, func). Check Documenter's build log for details.

Mounting Files

Oxygen.@staticfilesMacro
@staticfiles(folder::String, mountdir::String, headers::Vector{Pair{String,String}}=[])

Mount all files inside the /static folder (or user defined mount point)

source
Oxygen.@dynamicfilesMacro
@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

source
Oxygen.staticfilesFunction
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

source
Oxygen.dynamicfilesFunction
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

source

Autogenerated Docs

Oxygen.configdocsFunction
configdocs(docspath::String = "/docs", schemapath::String = "/schema")

Configure the default docs and schema endpoints

source
Missing docstring.

Missing docstring for enabledocs. Check Documenter's build log for details.

Missing docstring.

Missing docstring for disabledocs. Check Documenter's build log for details.

Missing docstring.

Missing docstring for isdocsenabled. Check Documenter's build log for details.

Oxygen.mergeschemaFunction
mergeschema(route::String, customschema::Dict)

Merge the schema of a specific route

mergeschema(customschema::Dict)

Merge the top-level autogenerated schema with a custom schema

source

Helper functions

Oxygen.Core.Util.formdataFunction
formdata(request::HTTP.Request)

Read the html form data from the body of a HTTP.Request

source
formdata(request::HTTP.Response)

Read the html form data from the body of a HTTP.Response

source
Oxygen.Core.Util.htmlFunction
html(content::String; status::Int, headers::Vector{Pair}) :: HTTP.Response

A convenience function to return a String that should be interpreted as HTML

source
Oxygen.Core.Util.textFunction
text(request::HTTP.Request)

Read the body of a HTTP.Request as a String

source
text(response::HTTP.Response)

Read the body of a HTTP.Response as a String

source
text(content::String; status::Int, headers::Vector{Pair}) :: HTTP.Response

A convenience function to return a String that should be interpreted as plain text

source
Oxygen.Core.Util.fileFunction
file(filepath::String; loadfile=nothing, status = 200, headers = []) :: HTTP.Response

Reads 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 the open function.
  • 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.
source
Oxygen.Core.Util.xmlFunction
xml(content::String; status::Int, headers::Vector{Pair}) :: HTTP.Response

A convenience function to return a String that should be interpreted as XML

source
Oxygen.Core.Util.jsFunction
js(content::String; status::Int, headers::Vector{Pair}) :: HTTP.Response

A convenience function to return a String that should be interpreted as JavaScript

source
Oxygen.Core.Util.jsonFunction
json(request::HTTP.Request; keyword_arguments...)

Read the body of a HTTP.Request as JSON with additional arguments for the read/serializer.

source
json(request::HTTP.Request, classtype; keyword_arguments...)

Read the body of a HTTP.Request as JSON with additional arguments for the read/serializer into a custom struct.

source
json(response::HTTP.Response; keyword_arguments)

Read the body of a HTTP.Response as JSON with additional keyword arguments

source
json(response::HTTP.Response, classtype; keyword_arguments)

Read the body of a HTTP.Response as JSON with additional keyword arguments and serialize it into a custom struct

source
json(content::Any; status::Int, headers::Vector{Pair}) :: HTTP.Response

A convenience function to return a String that should be interpreted as JSON

source
json(content::Vector{UInt8}; status::Int, headers::Vector{Pair}) :: HTTP.Response

A 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.

source
Oxygen.Core.Util.cssFunction
css(content::String; status::Int, headers::Vector{Pair}) :: HTTP.Response

A convenience function to return a String that should be interpreted as CSS

source
Oxygen.Core.Util.binaryFunction
binary(request::HTTP.Request)

Read the body of a HTTP.Request as a Vector{UInt8}

source
binary(content::Vector{UInt8}; status::Int, headers::Vector{Pair}) :: HTTP.Response

A convenience function to return a Vector of UInt8 that should be interpreted as binary data

source

Repeat Tasks & Cron Scheduling

Oxygen.@cronMacro
@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.

source
@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.

source
Oxygen.startcronjobsFunction
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

source
Oxygen.stopcronjobsFunction
stopcronjobs()

Stop each background task by toggling a global reference that all cron jobs reference

source
Missing docstring.

Missing docstring for clearcronjobs. Check Documenter's build log for details.

Extra's

Oxygen.routerFunction

No documentation found.

Binding Oxygen.Core.AutoDoc.router does not exist.

source
Oxygen.internalrequestFunction
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

source