Skip to content

Commit

Permalink
README: @HTTPRoute / @JSONRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
swhitty committed Oct 29, 2023
1 parent a445fa6 commit 991566f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,36 @@ protocol WSHandler {

`WSHandler` facilitates the exchange of a pair `AsyncStream<WSFrame>` containing the raw websocket frames sent over the connection. While powerful, it is more convenient to exchange streams of messages via [`WebSocketHTTPHandler`](#websockethttphandler).

## Preview Macro Handler

The branch [`preview/macro`](https://github.com/swhitty/FlyingFox/tree/preview/macro) contains an experimental preview implementation where handlers can annotate its functions with routes:

```swift
@HTTPHandler
struct MyHandler {

@HTTPRoute("/ping")
func ping() { }

@HTTPRoute("/pong")
func getPong(_ request: HTTPRequest) -> HTTPResponse {
HTTPResponse(statusCode: .accepted)
}

@JSONRoute("POST /account")
func createAccount(body: AccountRequest) -> AccountResponse {
AccountResponse(id: UUID(), balance: body.balance)
}
}

let server = HTTPServer(port: 80, handler: MyHandler())
try await server.start()
```

The annotations are implemented via [SE-0389 Attached Macros](https://github.com/apple/swift-evolution/blob/main/proposals/0389-attached-macros.md) available in Swift 5.9 and later.

Read more [here](https://github.com/swhitty/FlyingFox/tree/preview/macro#preview-macro-handler).

# FlyingSocks

Internally, FlyingFox uses a thin wrapper around standard BSD sockets. The `FlyingSocks` module provides a cross platform async interface to these sockets;
Expand Down

0 comments on commit 991566f

Please sign in to comment.