Pete's Alley - Routing

Written by Rich Morin.

Contents: (hide) (show)

Path:  AreasContentOverviews

Precis:  how we perform request routing for Pete's Alley

Our approach to request routing is fairly idiomatic. We use the :show action (and minor variations such as :show_code) for most tasks, only inventing new actions when forced to do so.

The InfoToml Actor maintains an in-memory version of the TOML file tree. Any time that we need to specify a file path, we do so in terms of a key that refers to an existing TOML file. However, we may modify the key to get to related files.

Here are all of our routes, from router.ex. We don’t use the resources macro, as it wouldn’t help much and it would obscure the basic structure:

get   "/area",            AreaController,     :show
get   "/reload",          AreaController,     :reload

get   "/clear",           ClearController,    :clear_form
post  "/clear",           ClearController,    :clear_post

get   "/dash",            DashController,     :show
get   "/dash/code",       DashController,     :show_code
get   "/dash/data",       DashController,     :show_data
get   "/dash/links",      DashController,     :show_links
get   "/dash/make",       DashController,     :show_make
get   "/dash/refs",       DashController,     :show_refs
get   "/dash/tags",       DashController,     :show_tags

get   "/edit",            EditController,     :edit_form
post  "/edit",            EditController,     :edit_post

get   "/item",            ItemController,     :show

get   "/mail/feed",       MailController,     :feed_form
post  "/mail/feed",       MailController,     :feed_post

get   "/search/find",     SearchController,   :find
post  "/search/show",     SearchController,   :show

get   "/slide",           SlideController,    :show

get   "/source",          SourceController,   :show
get   "/source/down",     SourceController,   :down

get   "/",                TextController,     :show
get   "/text",            TextController,     :show

get   "/*zoo",            ZooController,      :show

AreaController

get   "/area",            AreaController,     :show

# Show the index for a specified area:
#
#   /area?key=Areas/_area.toml
#   /area?key=Areas/Content/_area.toml
#   /area?key=Areas/Content/HowTos/_area.toml

get   "/reload",          AreaController,     :reload

# Reload `InfoToml`, the Elixir agent that maintains the in-memory
# version of the TOML file tree.  (For security, this action is only
# available to clients on the same Local Area Network.)

ClearController

get   "/clear",           ClearController,    :clear_form
post  "/clear",           ClearController,    :clear_post

# Display a "clear" form; clear selections upon submission.

DashController

get   "/dash",            DashController,     :show

# Show an index page of the available dashboards.

get   "/dash/code",       DashController,     :show_code
get   "/dash/data",       DashController,     :show_data
get   "/dash/links",      DashController,     :show_links
get   "/dash/make",       DashController,     :show_make
get   "/dash/refs",       DashController,     :show_refs
get   "/dash/tags",       DashController,     :show_tags

# Show individual dashboard pages.

EditController

get   "/item/edit",       EditController,     :edit_form
post  "/item/edit",       EditController,     :edit_post

# Display an item editing page; accept the submission.

ItemController

get   "/item",            ItemController,     :show

# Display a specified item, possibly bringing in content from
# ancillary files (eg, `text.*.toml`):
#
#   /item?key=Areas/Catalog/Hardware/Anova_PC/main.toml

MailController

get   "/mail/feed",       MailController,     :feed_form
post  "/mail/feed",       MailController,     :feed_post

# Display a feedback editing page; accept the submission.

SearchController

get   "/search/find",     SearchController,   :find
post  "/search/show",     SearchController,   :show

# Display a "search" form; do a search upon submission.

SlideController

get   "/slide",           SlideController,    :show

# Display a set of presentation slides.

SourceController

get   "/source",          SourceController,   :show

# Display the specified TOML source file:
#
#   /source?key=_schemas/main.toml
#   /source?key=_text/usage.toml
#   /source?key=Areas/Catalog/Hardware/Anova_PC/main.toml

get   "/source/down",     SourceController,   :down

# Download the specified TOML source file:
#
#   /source/down?key=_schemas/main.toml
#   /source/down?key=_text/usage.toml
#   /source/down?key=Areas/Catalog/Hardware/Anova_PC/main.toml

TextController

get   "/",                TextController,     :show
get   "/text",            TextController,     :show

# Show the specified text page:
#
#   /text?key=_text/home.toml     # "/" also works for this.
#   /text?key=_text/usage.toml

ZooController

get   "/*zoo",            ZooController,      :show

# Redirect to / with a nastygram:
#
#   /foo