Genie.Router.Route
— Typemutable struct Route
Representation of a route object
Genie.Router.Channel
— Typemutable struct Channel
Representation of a WebSocket Channel object
Base.show
— Functionshow([io::IO = stdout], x)
Write a text representation of a value x
to the output stream io
. New types T
should overload show(io::IO, x::T)
. The representation used by show
generally includes Julia-specific formatting and type information, and should be parseable Julia code when possible.
repr
returns the output of show
as a string.
For a more verbose human-readable text output for objects of type T
, define show(io::IO, ::MIME"text/plain", ::T)
in addition. Checking the :compact
IOContext
key (often checked as get(io, :compact, false)::Bool
) of io
in such methods is recommended, since some containers show their elements by calling this method with :compact => true
.
See also print
, which writes un-decorated representations.
Examples
julia> show("Hello World!")
"Hello World!"
julia> print("Hello World!")
Hello World!
show(io::IO, mime, x)
The display
functions ultimately call show
in order to write an object x
as a given mime
type to a given I/O stream io
(usually a memory buffer), if possible. In order to provide a rich multimedia representation of a user-defined type T
, it is only necessary to define a new show
method for T
, via: show(io, ::MIME"mime", x::T) = ...
, where mime
is a MIME-type string and the function body calls write
(or similar) to write that representation of x
to io
. (Note that the MIME""
notation only supports literal strings; to construct MIME
types in a more flexible manner use MIME{Symbol("")}
.)
For example, if you define a MyImage
type and know how to write it to a PNG file, you could define a function show(io, ::MIME"image/png", x::MyImage) = ...
to allow your images to be displayed on any PNG-capable AbstractDisplay
(such as IJulia). As usual, be sure to import Base.show
in order to add new methods to the built-in Julia function show
.
Technically, the MIME"mime"
macro defines a singleton type for the given mime
string, which allows us to exploit Julia's dispatch mechanisms in determining how to display objects of any given type.
The default MIME type is MIME"text/plain"
. There is a fallback definition for text/plain
output that calls show
with 2 arguments, so it is not always necessary to add a method for that case. If a type benefits from custom human-readable output though, show(::IO, ::MIME"text/plain", ::T)
should be defined. For example, the Day
type uses 1 day
as the output for the text/plain
MIME type, and Day(1)
as the output of 2-argument show
.
Examples
julia> struct Day
n::Int
end
julia> Base.show(io::IO, ::MIME"text/plain", d::Day) = print(io, d.n, " day")
julia> Day(1)
1 day
Container types generally implement 3-argument show
by calling show(io, MIME"text/plain"(), x)
for elements x
, with :compact => true
set in an IOContext
passed as the first argument.
Base.show(io::IO, ex::RuntimeException)
Custom printing of RuntimeException
Base.show(io::IO, ex::FileExistsException)
Custom printing for FileExistsException
Genie.Router.Params
— Typemutable struct Params{T}
Collection of key value pairs representing the parameters of the current request - response cycle.
Genie.Router.ispayload
— Functionispayload(req::HTTP.Request)
True if the request can carry a payload - that is, it's a POST
, PUT
, or PATCH
request
ispayload()
True if the request can carry a payload - that is, it's a POST
, PUT
, or PATCH
request
Genie.Router.route_request
— Functionroute_request(req::Request, res::Response) :: Response
First step in handling a request: sets up params collection, handles query vars, negotiates content.
Genie.Router.route_ws_request
— Functionroute_ws_request(req::Request, msg::String, ws_client::HTTP.WebSockets.WebSocket) :: String
First step in handling a web socket request: sets up params collection, handles query vars.
Base.push!
— Functionpush!(collection, items...) -> collection
Insert one or more items
in collection
. If collection
is an ordered container, the items are inserted at the end (in the given order).
Examples
julia> push!([1, 2, 3], 4, 5, 6)
6-element Vector{Int64}:
1
2
3
4
5
6
If collection
is ordered, use append!
to add all the elements of another collection to it. The result of the preceding example is equivalent to append!([1, 2, 3], [4, 5, 6])
. For AbstractSet
objects, union!
can be used instead.
See sizehint!
for notes about the performance model.
See also pushfirst!
.
Genie.Router.route
— FunctionNamed Genie routes constructors.
Genie.Router.channel
— FunctionNamed Genie channels constructors.
Genie.Router.routename
— Functionroutename(params) :: Symbol
Computes the name of a route.
Genie.Router.channelname
— Functionchannelname(params) :: Symbol
Computes the name of a channel.
Genie.Router.baptizer
— Functionbaptizer(params::Union{Route,Channel}, parts::Vector{String}) :: Symbol
Generates default names for routes and channels.
Genie.Router.named_routes
— FunctionThe list of the defined named routes.
Genie.Router.routes
— Functionroutes() :: Vector{Route}
Returns a vector of defined routes.
Genie.Router.named_channels
— Functionnamed_channels() :: Dict{Symbol,Any}
The list of the defined named channels.
Genie.Router.channels
— Functionchannels() :: Vector{Channel}
Returns a vector of defined channels.
Genie.Router.get_route
— FunctionGets the Route
corresponding to routename
Missing docstring for routes
. Check Documenter's build log for details.
Missing docstring for channels
. Check Documenter's build log for details.
Genie.Router.delete!
— Functiondelete!(route_name::Symbol)
Removes the route with the corresponding name from the routes collection and returns the collection of remaining routes.
Genie.Router.to_link
— FunctionGenerates the HTTP link corresponding to route_name
using the parameters in d
.
Generates the HTTP link corresponding to route_name
using the parameters in route_params
.
Genie.Router.tolink
— FunctionGenerates the HTTP link corresponding to route_name
using the parameters in d
.
Generates the HTTP link corresponding to route_name
using the parameters in route_params
.
Genie.Router.link_to
— FunctionGenerates the HTTP link corresponding to route_name
using the parameters in d
.
Generates the HTTP link corresponding to route_name
using the parameters in route_params
.
Genie.Router.linkto
— FunctionGenerates the HTTP link corresponding to route_name
using the parameters in d
.
Generates the HTTP link corresponding to route_name
using the parameters in route_params
.
Genie.Router.toroute
— FunctionGenerates the HTTP link corresponding to route_name
using the parameters in d
.
Generates the HTTP link corresponding to route_name
using the parameters in route_params
.
Genie.Router.route_params_to_dict
— Functionroute_params_to_dict(route_params)
Converts the route params to a Dict
.
Genie.Router.action_controller_params
— Functionaction_controller_params(action::Function, params::Params) :: Nothing
Sets up the :action_controller, :action, and :controller key - value pairs of the params
collection.
Missing docstring for run_hook
. Check Documenter's build log for details.
Genie.Router.match_routes
— Functionmatch_routes(req::Request, res::Response, params::Params) :: Union{Route,Nothing}
Matches the invoked URL to the corresponding route, sets up the execution environment and invokes the controller method.
Genie.Router.match_channels
— Functionmatch_channels(req::Request, msg::String, ws_client::HTTP.WebSockets.WebSocket, params::Params) :: String
Matches the invoked URL to the corresponding channel, sets up the execution environment and invokes the channel controller method.
Genie.Router.parse_route
— Functionparse_route(route::String, context::Module = @__MODULE__) :: Tuple{String,Vector{String},Vector{Any}}
Parses a route and extracts its named params and types. context
is used to access optional route parts types.
Genie.Router.parse_channel
— Functionparse_channel(channel::String) :: Tuple{String,Vector{String},Vector{Any}}
Parses a channel and extracts its named parms and types.
Genie.Router.extract_uri_params
— Functionextract_uri_params(uri::String, regex_route::Regex, param_names::Vector{String}, param_types::Vector{Any}, params::Params) :: Bool
Extracts params from request URI and sets up the params
Dict
.
Genie.Router.extract_get_params
— Functionextract_get_params(uri::URI, params::Params) :: Bool
Extracts query vars and adds them to the execution params
Dict
.
Genie.Router.extract_post_params
— Functionextract_post_params(req::Request, params::Params) :: Nothing
Parses POST variables and adds the to the params
Dict
.
Genie.Router.extract_request_params
— Functionextract_request_params(req::HTTP.Request, params::Params) :: Nothing
Sets up the params
key-value pairs corresponding to a JSON payload.
Genie.Router.content_type
— Functioncontent_type(req::HTTP.Request) :: String
Gets the content-type of the request.
Genie.Router.content_length
— Functioncontent_length(req::HTTP.Request) :: Int
Gets the content-length of the request.
Genie.Router.request_type_is
— Functionrequest_type_is(req::HTTP.Request, request_type::Symbol) :: Bool
Checks if the request content-type is of a certain type.
Genie.Router.request_type
— Functionrequest_type(req::HTTP.Request) :: Symbol
Gets the request's content type.
Genie.Router.nested_keys
— Functionnested_keys(k::String, v, params::Params) :: Nothing
Utility function to process nested keys and set them up in params
.
Genie.Router.setup_base_params
— Functionsetup_base_params(req::Request, res::Response, params::Dict{Symbol,Any}) :: Dict{Symbol,Any}
Populates params
with default environment vars.
Genie.Router.to_response
— Functionto_response(action_result) :: Response
Converts the result of invoking the controller action to a Response
.
Genie.Router.params
— Functionfunction params()
The collection containing the request variables collection.
Missing docstring for _params_
. Check Documenter's build log for details.
Genie.Router.request
— Functionfunction request()
The request object.
Genie.Router.response_type
— Functionresponse_type{T}(params::Dict{Symbol,T}) :: Symbol
response_type(params::Params) :: Symbol
Returns the content-type of the current request-response cycle.
response_type{T}(check::Symbol, params::Dict{Symbol,T}) :: Bool
Checks if the content-type of the current request-response cycle matches check
.
Genie.Router.append_to_routes_file
— Functionappend_to_routes_file(content::String) :: Nothing
Appends content
to the app's route file.
Genie.Router.is_static_file
— Functionis_static_file(resource::String) :: Bool
Checks if the requested resource is a static file.
Missing docstring for to_uri
. Check Documenter's build log for details.
Genie.Router.escape_resource_path
— Functionescape_resource_path(resource::String)
Cleans up paths to resources.
Genie.Router.serve_static_file
— Functionserve_static_file(resource::String) :: Response
Reads the static file and returns the content as a Response
.
Genie.Router.preflight_response
— Functionpreflight_response() :: HTTP.Response
Sets up the preflight CORS response header.
Genie.Router.response_mime
— Functionresponse_mime()
Returns the MIME type of the response.
Genie.Router.file_path
— Functionfile_path(resource::String; within_doc_root = true, root = Genie.config.server_document_root) :: String
Returns the path to a resource file. If within_doc_root
it will automatically prepend the document root to resource
.
Genie.Router.filepath
— Functionfile_path(resource::String; within_doc_root = true, root = Genie.config.server_document_root) :: String
Returns the path to a resource file. If within_doc_root
it will automatically prepend the document root to resource
.
Genie.Router.pathify
— Functionpathify(x) :: String
Returns a proper URI path from a string x
.
Genie.Router.file_extension
— Functionfile_extension(f) :: String
Returns the file extesion of f
.
Genie.Router.file_headers
— Functionfile_headers(f) :: Dict{String,String}
Returns the file headers of f
.
Missing docstring for ormatch
. Check Documenter's build log for details.