Dance.Logger.log
— Methodlog(error)
Logging of timestamp & error message
- If Prod: Write to log file
- Else: Output te REPL
Dance.JSONRenderer.render
— Methodrender(;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 to
Dict{String, String} here, as can be blank (status_code !=200)
Dance.CoreEngine.build_route_params_dict
— Methodbuild_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.close_server
— Methodclose_server()
Stop Flamenco server
Dance.CoreEngine.map_route_function_output
— Methodmap_route_function_output()
Output from route.action can contain optional HTTP Headers params dict
Dance.CoreEngine.process_backend_function
— Methodprocess_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.render
— Methodrender(;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_200
— Methodrender_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_400
— Methodrender_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_404
— Methodrender_404(;endpoint::String) :: Dict{Symbol, Union{Dict{String, String}, Int16, String}}
Render HTTP 404 response
Dance.CoreEngine.render_405
— Methodrender_405(;endpoint::String, html_file::String) :: Dict{Symbol, Union{Dict{String, String}, Int16, String}}
Render HTTP 405 response
Dance.CoreEngine.render_500
— Methodrender_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.respond
— Methodrespond(; headers::Dict{String, String}, status_code::Int16, body::String) :: String
Return response for specified parameters
Dance.CoreEngine.start_server
— Methodstart_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_segments
— Methodget_path_param_segments(;request_path::String, route_path::String)
Parse route.path and match param sections with corresponding request path segments
Dance.URIUtils.get_path_segments
— Methodget_path_segments(path::String)
Array from breaking path at slashes
Dance.Configuration.is_prod
— Methodis_prod(file_path)
Check if is Production environment
Dance.Configuration.populate
— Methodpopulate(file_path)
- Read settings/Global.jl from project
- Populate/update Settings dict accordingly
Dance.HTMLRenderer.populate
— Methodpopulate(;html_file::String="", data::Union{DataFrames.DataFrame, Dict, String})
Populate supplied HTML with data, by replacing @data
param
Dance.HTMLRenderer.render
— Methodrender(;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 to
Dict{String, String} here, as can be blank (status_code !=200)
Dance.StaticRenderer.render
— Methodrender(;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 to
Dict{String, String} here, as can be blank (status_code !=200)
Dance.Router.delete_routes!
— Methoddelete_routes!()
Empty ROUTES ordered dict
Only called from tests as of now
Dance.Router.get_route
— Methodget_route(route_path::String)
Search ROUTES ordered dict for route component from specified path
Dance.Router.output_file_as_string
— Methodoutput_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.path_already_exists
— Methodpath_already_exists(path::String)
Verify if ROUTES ordered dict already has existing entry for specified path
Dance.Router.populate
— Methodpopulate(file_path)
Register Routes from Configuration.Settings[:routes_filename]
file
Dance.Router.remove_trailing_slash
— Methodremove_trailing_slash(path::String)
Remove eventual trailing slash, if not index url
Dance.Router.route
— Methodroute(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_group
— Methodroute_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_dir
— Methodstatic_dir(route_prefix::String, dir_path::String)
Parse supplied directory path and create routes for each item
Dance.CoreRenderer.render
— Methodrender(;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 to
Dict{String, String} here, as can be blank (status_code !=200)
Dance.launch
— Methodlaunch(start_server::Bool)
Launch either (depending on start_server
param):
- Web server via selected engine
- REPL
Dance.populate_load_path
— Methodpopulate_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_router
— Methodpopulate_router(file_path::String)
Populate Router.ROUTES OrderedDict (when including/compiling Julia files)
Dance.populate_settings
— Methodpopulate_settings(file_path::String)
Populate Configuration.Settings dict
Dance.start_project
— Functionstart_project(project_name::String, path::String=".")
- Specify new project name
- Copy
files
dir to root of new project
Dance.PayloadUtils.convert_array_to_dataframe
— Methodconvert_array_to_dataframe(array::Array{Any,1})
Convert Array{Any,1} to DataFrame
Dance.PayloadUtils.convert_dataframe_to_array
— Methodconvert_dataframe_to_array(df::DataFrames.DataFrame)
Convert DataFrame to Dict{Array}, including column names via first line of array