Athena Framework 0.16.0
This release focused on integrating the new Routing component into the framework as well as the introduction of the Athena monorepo.
Routing Component
Amber Router has served the framework well for the past few years. However, as alluded to in the last release, it was time for an upgrade. I’m happy to announce the Athena::Routing component is now finished and integrated into Athena Framework!
Just like all the other components, it can also be used outside of the ecosystem, such as other frameworks, to handle your routing needs. It has quite a few features, and none of the limitations of other Crystal routers:
- Is entirely regex based, allows using regex to define validations in order to determine if a given route should match
- Also supports route priorities and sub-domain matching
- Allows multiple routes with placeholders in the same location thanks to the previous bullet
- Built in support for default values
- Provides annotations that can be used for custom implementations
A regex router you say? That can’t be fast! Thanks to PCRE2’s JIT compilation using the fast-path API, it sure is. The main bottleneck is URI.decode
. Without that, the results are even better, otherwise is still faster than the other routers in every case except two.
Given routing is a core part of a web framework, this change does come with a few breaking changes. See the changelog for the full list.
Annotations
-
@[ATHA::Prefix(prefix: "/foo")]
=>@[ARTA::Route(path: "/foo")]
- Prefixes no longer check parent types. Define a single
ARTA::Route
with the prefix on each controller
- Prefixes no longer check parent types. Define a single
-
ATHA::*
routing annotations have been replaced withARTA::*
routing annotations
Trailing slashes are now taken into consideration
/foo
is a different route when compared to /foo/
. Be sure to be consistent and follow a common pattern throughout your application.
Route Parameter Syntax
Route parameters are now defined by wrapping the name within {}
, such as /user/{id}
. The primary benefit of this is allowing parameters within other segments, such as /foo{slug}bar
which would match everything between foo
and bar
. It also allows the format of the request path to be captured/restricted. E.g. /user/{id}.{_format?json}
, which would default to json
if not provided (/user/10
) or allow a custom format (/user/10.xml
). The routing component has a few special parameters, such as _format
, which will set the format of the request to the matched format if used. This can be especially useful for Athena’s content negotiation feature.
Athena Monorepo
As mentioned in How I migrated Athena to a Monorepo...and you can too, I have migrated Athena to a monorepo such that all of the components can be more easily maintained within a single repository. Given this is the first release after this change you will need to update the repository within shard.yml
in order to install the update. Athena Framework should now be installed as:
dependencies:
athena:
github: athena-framework/framework
version: ~> 0.16.0
The only difference being athena-framework/athena
=> athena-framework/framework
.
Checkout the release notes for a complete list of changes. As usual feel free to join me in the Athena Gitter channel if you have any suggestions, questions, or ideas. I’m also available on Discord (Blacksmoke16#0016
) or via Email.
P.S. Athena now has a Discord server!