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 1f56d59 commit 64acb5c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,27 +291,28 @@ let route = HTTPRoute("POST *", body: .json(where: "food == 'fish'"))

## Route Parameters

With Swift 5.9, closure routes can include parameters that are automatically extracted from the request and passed to the handler:
Handlers can extract parameter values from the request:

```swift
enum Beast: String, HTTPRouteParameterValue {
case fish
case dog
}

handler.appendRoute("GET /creature/:name?type=:beast") { (name: String, beast: Beast) -> HTTPResponse in
func handle(request: HTTPRequest) async throws -> HTTPResonse {
let name = request.routeParameters["name"]
let beast: Beast = request.routeParameters["beast"]
return HTTPResponse(statusCode: .ok)
}
```

All other handlers can extract parameter values from the request:
With Swift 5.9, closure routes can include parameters that are automatically extracted from the request and passed to the handler:

```swift
func handle(request: HTTPRequest) async throws -> HTTPResonse {
let name = request.routeParameters["name"]
let beast: Beast = request.routeParameters["beast"]
handler.appendRoute("GET /creature/:name?type=:beast") { (name: String, beast: Beast) -> HTTPResponse in
return HTTPResponse(statusCode: .ok)
}
```

## 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 64acb5c

Please sign in to comment.