Skip to content

Commit adb9b37

Browse files
authored
Update README.md
1 parent ad99428 commit adb9b37

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

README.md

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,26 +115,45 @@ await server.appendRoute(for: "GET /fish/*", to: routes)
115115

116116
`HTTPUnhandledError` is thrown if `RoutedHTTPHandler` is unable to handle the request with any of its registered handlers. `HTTP 404` is returned as the response.
117117

118-
### Wildcards
118+
### HTTPRoute
119119

120-
Routes can include wildcards which can be [pattern matched](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#ID426) against paths:
120+
Routes allow requests to be identified by `HTTPMethod` and path and can be [pattern matched](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#ID426) against requests:
121121

122122
```swift
123-
let HTTPRoute("/hello/*/world")
123+
let HTTPRoute("/hello/world")
124124

125-
route ~= "/hello/fish/world" // true
126-
route ~= "GET /hello/fish/world" // true
127-
route ~= "POST hello/dog/world/" // true
128-
route ~= "/hello/world" // false
125+
route ~= HTTPRequest(method: .GET, path: "/hello/world") // true
126+
route ~= HTTPRequest(method: .POST, path: "/hello/world") // true
127+
route ~= HTTPRequest(method: .GET, path: "/hello/") // false
129128
```
130129

131-
By default routes accept all HTTP methods, but specific methods can be supplied:
130+
Routes can include specific methods to match against:
132131

133132
```swift
134133
let HTTPRoute("GET /hello/world")
135134

136-
route ~= "GET /hello/world" // true
137-
route ~= "PUT /hello/world" // false
135+
route ~= HTTPRequest(method: .GET, path: "/hello/world") // true
136+
route ~= HTTPRequest(method: .POST, path: "/hello/world") // false
137+
```
138+
139+
And can use wildcards within the path
140+
141+
```swift
142+
let HTTPRoute("GET /hello/*/world")
143+
144+
route ~= HTTPRequest(method: .GET, path: "/hello/fish/world") // true
145+
route ~= HTTPRequest(method: .POST, path: "/hello/dog/world") // true
146+
route ~= HTTPRequest(method: .POST, path: "/hello/fish/sea") // false
147+
```
148+
149+
Trailing wildcards match all trailing path components:
150+
151+
```swift
152+
let HTTPRoute("GET /hello/*")
153+
154+
route ~= HTTPRequest(method: .GET, path: "/hello/fish/world") // true
155+
route ~= HTTPRequest(method: .POST, path: "/hello/dog/world") // true
156+
route ~= HTTPRequest(method: .POST, path: "/hello/fish/deep/blue/sea") // true
138157
```
139158

140159
## AsyncSocket / PollingSocketPool

0 commit comments

Comments
 (0)