Getting Started with Routing¶
Routing (vapor/routing) is a small framework for routing things like HTTP requests. It lets you register and lookup routes in a router using nested, dynamic path components.
For example, the routing package can help you route a request like the following and collect the values of the dynamic components.
This package is included with Vapor and exported by default. You will have access to all
Routing APIs when you import
If you use Vapor, most of Routing's APIs will be wrapped by more convenient methods. See [Vapor → Routing] for more information.
The Routing package is lightweight, pure-Swift, and has very few dependencies. This means it can be used as a routing framework for any Swift project—even one not using Vapor.
To include it in your package, add the following to your
// swift-tools-version:4.0 import PackageDescription let package = Package( name: "Project", dependencies: [ ... .package(url: "https://github.com/vapor/routing.git", from: "3.0.0"), ], targets: [ .target(name: "Project", dependencies: ["Routing", ... ]) ] )
import Routing to access the APIs.
Some of this guide may contain Vapor-specific APIs, however most of it should be applicable to the Routing package in general. Visit the API Docs for Routing-specific API info.