Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README and comments #281

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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` libraries.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..., but it can support TLS and HTTP2 via the HummingbirdTLS and HummingbirdHTTP2 libraries.
Wouldn't modules be clearer? As these features are in the hummingbird package itself, this might lead people to search for packages with those names


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 enum XCTRouterTestingSetup {
case router
}

/// Extends `HBApplicationBuilder` to support testing of applications
/// Extends `HBApplicationB` to support testing of applications
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo?

///
/// 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 enum 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