Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
swhitty authored Jul 13, 2024
1 parent f8a08af commit 7673faf
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ route ~= HTTPRequest(method: .GET, path: "/hello/dog/world") // true
route ~= HTTPRequest(method: .GET, path: "/hello/fish/sea") // false
```

Routes can include named [parameters](#route-parameters) that match like wildcards, while allowing their value to be extracted from the request.
Routes can include named [parameters](#route-parameters) that match like wildcards allowing handlers to extract the value from the request.

```swift
let route = HTTPRoute("GET /hello/:beast/world")
Expand Down Expand Up @@ -291,7 +291,7 @@ let route = HTTPRoute("POST *", body: .json(where: "food == 'fish'"))

## Route Parameters

Routes can include named parameters within a path or query item, allowing handlers to extract these values from the matched `HTTPRequest`:
Routes can include named parameters within a path or query item using the `:` prefix. Any string supplied to this parameter will match like a wildcard `*`. Handlers can then use `request.routePamaters` to access the value of the string.

```swift
handler.appendRoute("GET /creature/:name?type=:beast") { request in
Expand All @@ -301,7 +301,7 @@ handler.appendRoute("GET /creature/:name?type=:beast") { request in
}
```

When using Swift 5.9+, route parameters can be automatically extracted and mapped to closure parameters of handlers:
When using Swift 5.9+, route parameters can be automatically extracted and mapped to closure parameters of handlers.

```swift
enum Beast: String, HTTPRouteParameterValue {
Expand All @@ -314,6 +314,8 @@ handler.appendRoute("GET /creature/:name?type=:beast") { (name: String, beast: B
}
```

`String`, `Int`, `Double`, `Bool` and any custom type that conforms to `HTTPRouteParameterValue` can be extracted.

## WebSockets
`HTTPResponse` can switch the connection to the [WebSocket](https://datatracker.ietf.org/doc/html/rfc6455) protocol by provding a `WSHandler` within the response payload.

Expand Down

0 comments on commit 7673faf

Please sign in to comment.