Skip to content

Commit

Permalink
Update README and comments (#281)
Browse files Browse the repository at this point in the history
* Update README and comments

* Updates from PR comments
  • Loading branch information
adam-fowler authored Nov 20, 2023
1 parent b4c892d commit 8e01636
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,32 @@
</a>
</p>

Lightweight, flexible server framework written in Swift.

Hummingbird consists of three main components, the core HTTP server, a minimal web application framework and the extension modules.
Lightweight, flexible, modern server framework written in Swift.

## HummingbirdCore

HummingbirdCore contains a Swift NIO based HTTP server. You will find the code for it in the [hummingbird-core](https://github.com/hummingbird-project/hummingbird-core) repository. The HTTP server is initialized with a object conforming to protocol `HBHTTPResponder` which defines how your server responds to an HTTP request. The HTTP server can be extended to support TLS and HTTP2 via the `HummingbirdTLS` and `HummingbirdHTTP2` libraries also available in the hummingbird-core repository.
HummingbirdCore contains a Swift NIO based server framework. The server framework `HBServer` can be used to support many protocols but is primarily designed to support HTTP. By default it is setup to be an HTTP/1.1 server, but it can support TLS and HTTP2 via the `HummingbirdTLS` and `HummingbirdHTTP2` modules.

HummingbirdCore can be used separately from Hummingbird if you want to write your own web application framework.

## Hummingbird

Hummingbird is a lightweight and flexible web application framework that runs on top of HummingbirdCore. It is designed to require the minimum number of dependencies: `swift-backtrace`, `swift-log`, `swift-nio`, `swift-nio-extras`, `swift-service-lifecycle` and `swift-metrics` and makes no use of Foundation.

It provides a router for directing different endpoints to their handlers, middleware for processing requests before they reach your handlers and processing the responses returned, support for adding channel handlers to extend the HTTP server, extending the core `HBApplication`, `HBRequest` and `HBResponse` classes and providing custom encoding/decoding of `Codable` objects.
Hummingbird is a lightweight and flexible web application framework that runs on top of HummingbirdCore. It is designed to require the minimum number of dependencies and makes no use of Foundation.

The interface is fairly standard. Anyone who has had experience of Vapor, Express.js etc will recognise most of the APIs. Simple setup is as follows
It provides a router for directing different endpoints to their handlers, middleware for processing requests before they reach your handlers and processing the responses returned, support for adding channel handlers to extend the HTTP server and providing custom encoding/decoding of `Codable` objects.

```swift
import Hummingbird

let app = HBApplication(configuration: .init(address: .hostname("127.0.0.1", port: 8080)))
app.router.get("hello") { request -> String in
let router = HBRouterBuilder()
router.get("hello") { request -> String in
return "Hello"
}
try app.start()
app.wait()
let app = HBApplication(
responder: router.buildResponder(),
configuration: .init(address: .hostname("127.0.0.1", port: 8080))
)
try await app.runService()
```

## Hummingbird Extensions
Expand Down
16 changes: 7 additions & 9 deletions Sources/Hummingbird/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,18 @@ public final class HBApplicationContext: Sendable {
}
}

/// Application builder class. Brings together all the components of Hummingbird together
/// Application class. Brings together all the components of Hummingbird together
///
/// Setup an HBApplicationBuilder, setup your application middleware, encoders, routes etc and then either
/// add call `build` to create an `HBApplication` which you add to your ServiceLifecycle `ServiceGroup` or
/// run separately with `buildAndRun`.
/// ```
/// let app = HBApplicationBuilder()
/// app.middleware.add(MyMiddleware())
/// app.router.get("hello") { _ in
/// let router = HBRouterBuilder()
/// router.middleware.add(MyMiddleware())
/// router.get("hello") { _ in
/// return "hello"
/// }
/// try await app.buildAndRun()
/// let app = HBApplication(responder: router.buildResponder())
/// try await app.runService()
/// ```
/// Editing the application builder setup after calling `build` will produce undefined behaviour.
/// Editing the application setup after calling `runService` will produce undefined behaviour.
public struct HBApplication<Responder: HBResponder, ChannelSetup: HBChannelSetup & HTTPChannelHandler> {
// MARK: Member variables

Expand Down
9 changes: 5 additions & 4 deletions Sources/HummingbirdXCT/Application+XCT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public struct XCTRouterTestingSetup {
public static let router = XCTRouterTestingSetup()
}

/// Extends `HBApplicationBuilder` to support testing of applications
/// Extends `HBApplication` to support testing of applications
///
/// You use `buildAndTest` and `XCTExecute` to test applications. You can either create an
/// `.router` application which send request directly to the router for testing your code or a
Expand All @@ -37,11 +37,12 @@ public struct XCTRouterTestingSetup {
///
/// The example below is using the `.router` framework to test
/// ```
/// let app = HBApplicationBuilder()
/// app.router.get("/hello") { _ in
/// let router = HBRouterBuilder()
/// router.get("/hello") { _ in
/// return "hello"
/// }
/// app.buildAndTest(.router) { client in
/// let app = HBApplication(responder: router.buildResponder())
/// app.test(.router) { client in
/// // does my app return "hello" in the body for this route
/// client.XCTExecute(uri: "/hello", method: .GET) { response in
/// let body = try XCTUnwrap(response.body)
Expand Down

0 comments on commit 8e01636

Please sign in to comment.