Skip to content
/ Ditto Public

A lightweight routing system written in Swift.

License

Notifications You must be signed in to change notification settings

xspyhack/Ditto

Repository files navigation

Ditto

A lightweight routing system written in Swift.

Usage

let router = Router<Void>(schemes: ["ditto"])
let endpoint = Endpoint(url: URL(string: "ditto://foo/:bar")!)
let route = Route<Void>(endpoint: endpoint) { context in
    guard let bar: Int = try? context.argument(forKey: "bar") else {
        return false
    }
    print(bar) // 233
    return true
}

router.register(route)

let url = URL(string: "ditto://foo/233")!
if router.responds(to: url) {
    router.route(to: url)
}

Advanced

class Router {
    // Register home page route use silgen prefix `ditto:`
    // alligator://home
    // https://www.alligator.com/home
    @_silgen_name("ditto:/home")
    func home(context: Context<RoutingCoordinator>) -> Bool {
        return true
    }
}

License

Ditto is available under the MIT License. See the LICENSE file for more info.

About

A lightweight routing system written in Swift.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published