Krouton

Type-safe and compositional URL routing and reverse routing

License

License

GroupId

GroupId

com.natpryce
ArtifactId

ArtifactId

krouton
Last Version

Last Version

2.4.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

Krouton
Type-safe and compositional URL routing and reverse routing
Project URL

Project URL

https://github.com/npryce/krouton
Source Code Management

Source Code Management

https://github.com/npryce/krouton

Download krouton

How to add to project

<!-- https://jarcasting.com/artifacts/com.natpryce/krouton/ -->
<dependency>
    <groupId>com.natpryce</groupId>
    <artifactId>krouton</artifactId>
    <version>2.4.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.natpryce/krouton/
implementation 'com.natpryce:krouton:2.4.0.0'
// https://jarcasting.com/artifacts/com.natpryce/krouton/
implementation ("com.natpryce:krouton:2.4.0.0")
'com.natpryce:krouton:jar:2.4.0.0'
<dependency org="com.natpryce" name="krouton" rev="2.4.0.0">
  <artifact name="krouton" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.natpryce', module='krouton', version='2.4.0.0')
)
libraryDependencies += "com.natpryce" % "krouton" % "2.4.0.0"
[com.natpryce/krouton "2.4.0.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib jar 1.4.10
org.jetbrains.kotlin : kotlin-reflect jar 1.4.10
org.http4k : http4k-core jar 3.277.0

test (7)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-test jar 1.4.10
com.natpryce : hamkrest jar 1.4.2.0
org.http4k : http4k-testing-hamkrest jar 3.277.0
org.junit.jupiter : junit-jupiter-api jar 5.4.2
dev.minutest : minutest jar 1.7.0
org.junit.jupiter : junit-jupiter-engine jar 5.4.2
org.junit.platform : junit-platform-launcher jar 1.4.2

Project Modules

There are no modules declared in this project.

Krouton

Typesafe, compositional routing and reverse routing for Kotlin web apps and HTTP microservices.

Kotlin Build Status Maven Central Apache 2.0

Krouton provides a routing API for HTTP4K, but the core abstractions can be used with any web server library.

Examples

Principles

Type safe routing and reverse routing.

No reflection, annotations or classpath scanning.

Explicit, type-checked flow of data and control, instead of "spooky action at a distance" via reflection, annotations, classpath scanning, passing data in context maps or synthetic HTTP headers, or control flow via exceptions.

Separate code that routes and handles requests from definitions of URLs

  • URLs defined by constants (immutable objects)
  • Routing policy defined by operations on those constants
  • Routing done by functions/closures/objects that connect Krouton's routing policy API to a web server library.

Compositional: routes are composed from primitive parts and composition operators. User-defined routes can be used in exactly the same way as the predefined primitives.

Mandatory aspects of a resource locator go in the path

Query parameters are optional and are interpreted by the resource.

Routing policy operations

  • Parsing: UrlScheme<T>.parse(String) -> T?
  • Reverse Routing: UrlScheme<T>.path(T) -> String
  • Reporting: UrlScheme<T>.monitoredPath(T)-> String

Route composition

  • Append:
    • UrlScheme<T> + UrlScheme<U> -> UrlScheme<Tuple2<T,U>>
    • + operator supports appending paths for scalars and tuples, forming paths for tuples with up to five elements
    • UrlScheme<Unit> + UrlScheme<T> -> UrlScheme<T>
    • UrlScheme<T> + UrlScheme<Unit> -> UrlScheme<T>
  • Append fixed path element: UrlScheme<T> + String -> UrlScheme<T>
  • Restrict: UrlScheme<T> where ((T)->Boolean) -> UrlScheme<T>
  • Project: UrlScheme<T> asA Projection<T,U> -> UrlScheme<U>

What's with the version number?

The version number is {mental}.{major}.{minor}.{patch}. The last three digits are treated as a semantic version number. The first digit is incremented if there is a significant change in the mental model underpinning the library. A major version of zero always signifies a pre-release version, irrespective of the value of the first digit. The API of pre-release versions may go through significant changes in response to user feedback before the release of version x.1.0.0.

Versions

Version
2.4.0.0
2.3.1.3
2.3.1.2
2.3.1.1
2.3.1.0
2.3.0.0
2.3.0.0-RC1
2.2.0.0
2.1.0.0
2.0.8.0
2.0.7.0
2.0.6.0
2.0.5.0
2.0.4.0
2.0.1.0
2.0.0.0
1.3.0.0
1.2.0.0
1.1.0.1
1.1.0.0