Dance.Logger.logMethod
log(error)

Logging of timestamp & error message

  • If Prod: Write to log file
  • Else: Output te REPL
Dance.JSONRenderer.renderMethod
render(;headers::Dict{String, String}, status_code::Int16, data::Union{DataFrames.DataFrame, Dict}) :: Dict{Symbol, Union{Dict{String, String}, Int16, String}}

Output JSON renderer

Though status code is pre-supplied, can become 500

Cannot set headers type toDict{String, String} here, as can be blank (status_code !=200)

Dance.CoreEngine.build_route_params_dictMethod
build_route_params_dict(;request_route_segments::Array{String, 1}, route_path::String) :: Dict

Build dict of route params and corresponding values, by:

  • Parsing route.path for only segment sections
  • Looking-up request route segments at corresponding index
Dance.CoreEngine.process_backend_functionMethod
process_backend_function(;route::Router.Route, route_segments::Array{String, 1}, payload::String, headers::Dict{String, String}) :: Dict{Symbol, Union{Dict{String, String}, Int16, String}}

2 main cases

  • JSON POST request with payload
  • GET request

If error during process, render 500 response

Render 400 if badly supplied payload data

Dance.CoreEngine.renderMethod
render(;request_headers::Array, request_method::String, request_path::String, request_payload::String) :: String

Main entry point of HTTP Rendering

  • Invalid method will render 405 response
  • If error during process, render 500 response

Check Headers if was JSON request, to return 404 as JSON output

Dance.CoreEngine.render_200Method
render_200(;headers::Dict{String, String}, endpoint::String, data::OUTPUT_DATA_FORMATS, html_file::String) :: Dict{Symbol, Union{Dict{String, String}, Int16, String}}

Render HTTP 200 response

Dance.CoreEngine.render_400Method
render_400(;endpoint::String) :: Dict{Symbol, Union{Dict{String, String}, Int16, String}}

Render HTTP 400 response

No HTML output file required here, as limited to JSON request

Dance.CoreEngine.render_404Method
render_404(;endpoint::String) :: Dict{Symbol, Union{Dict{String, String}, Int16, String}}

Render HTTP 404 response

Dance.CoreEngine.render_405Method
render_405(;endpoint::String, html_file::String) :: Dict{Symbol, Union{Dict{String, String}, Int16, String}}

Render HTTP 405 response

Dance.CoreEngine.render_500Method
render_500(;endpoint::String, data::String, html_file::String, request_path::String) :: Dict{Symbol, Union{Dict{String, String}, Int16, String}}

Render HTTP 500 response

Only if NOT Prod: output error details to page

Dance.CoreEngine.respondMethod
respond(; headers::Dict{String, String}, status_code::Int16, body::String) :: String

Return response for specified parameters

Dance.CoreEngine.start_serverMethod
start_server(server_host::String, server_port::Int64) :: Nothing

Start Flamenco server and listen for incoming requests and return HTML or JSON body

Dance.URIUtils.get_path_param_segmentsMethod
get_path_param_segments(;request_path::String, route_path::String)

Parse route.path and match param sections with corresponding request path segments

Dance.HTMLRenderer.populateMethod
populate(;html_file::String="", data::Union{DataFrames.DataFrame, Dict, String})

Populate supplied HTML with data, by replacing @data param

Dance.HTMLRenderer.renderMethod
render(;headers::Dict{String, String}, status_code::Int16, data::Union{DataFrames.DataFrame, Dict, String}, html_file::String) :: Dict{Symbol, Union{Dict{String, String}, Int16, String}}

HTML renderer

status code is pre-supplied

Cannot set headers type toDict{String, String} here, as can be blank (status_code !=200)

Dance.StaticRenderer.renderMethod
render(;headers::Dict{String, String}, status_code::Int16, data::String) :: Dict{Symbol, Union{Dict{String, String}, Int16, String}}

Renderer to output static file as string

Cannot set headers type toDict{String, String} here, as can be blank (status_code !=200)

Dance.Router.get_routeMethod
get_route(route_path::String)

Search ROUTES ordered dict for route component from specified path

Dance.Router.output_file_as_stringMethod
output_file_as_string(file_path::String)

Read file_path as string and obtain corresponding mime-type based on file extension

First try searching in STATICDIR then try in project root, each time relative to routepath favicon.ico is special exception case

Dance.Router.populateMethod
populate(file_path)

Register Routes from Configuration.Settings[:routes_filename] file

Dance.Router.routeMethod
route(path::Union{Regex, String}, action::Function; method::String=POST, endpoint=EP_JSON, html_file::String=Configuration.Settings[:html_base_filename]*".html")

Create new Route and add to ROUTES ordered dict

  • If path is Regex, convert to String for storage (Route has has_regex field)
  • Remove trailing slash
Dance.Router.route_groupMethod
route_group(routes::Array; route_prefix::String="", method::String="", endpoint::String="", html_file::String=Configuration.Settings[:html_base_filename]*".html")

Loop through array of named tuple routes, calling route function

  • automatically prepend route_prefix to route path (if supplied)
  • if other parameters supplied as function kwargs, set route parameters accordingly
Dance.Router.static_dirMethod
static_dir(route_prefix::String, dir_path::String)

Parse supplied directory path and create routes for each item

Dance.CoreRenderer.renderMethod
render(;headers::Dict{String, String}=Dict("" => ""), status_code::Int16, endpoint::String, data::Union{DataFrames.DataFrame, Dict, String}, html_file::String) :: Dict{Symbol, Union{Dict{String, String}, Int16, String}}

Generic web output rendering function

Depending on endpoint field, render JSON or HTML string

Cannot set headers type toDict{String, String} here, as can be blank (status_code !=200)

Dance.launchMethod
launch(start_server::Bool)

Launch either (depending on start_server param):

  • Web server via selected engine
  • REPL
Dance.populate_load_pathMethod
populate_load_path(file_path::String; ignore_dirs::Array{String, 1})
  • Read Settings dict for routes filepath

  • Get static dir by parsing routes.jl

  • Optional: array of other paths to ignore

Dance.populate_routerMethod
populate_router(file_path::String)

Populate Router.ROUTES OrderedDict (when including/compiling Julia files)

Dance.start_projectFunction
start_project(project_name::String, path::String=".")
  • Specify new project name
  • Copy files dir to root of new project