A light-weight server-side service framework written in the Swift programming language.

Overview

Build - Main Branch Swift 5.3, 5.4 and 5.5 Tested Ubuntu 16.04 and 20.04 Tested CentOS 8 Tested Amazon Linux 2 Tested Join the Smoke Server Side community on gitter Apache 2

Smoke Framework

The Smoke Framework is a light-weight server-side service framework written in Swift and using SwiftNIO for its networking layer by default. The framework can be used for REST-like or RPC-like services and in conjunction with code generators from service models such as Swagger/OpenAPI.

The framework has built in support for JSON-encoded request and response payloads.

Support Policy

SmokeFramework follows the same support policy as followed by SmokeAWS here.

Conceptual Overview

The Smoke Framework provides the ability to specify handlers for operations your service application needs to perform. When a request is received, the framework will decode the request into the operation's input. When the handler returns, its response (if any) will be encoded and sent in the response.

Each invocation of a handler is also passed an application-specific context, allowing application-scope or invocation-scope entities such as other service clients to be passed to operation handlers. Using the context allows operation handlers to remain pure functions (where its return value is determined by the function's logic and input values) and hence easily testable.

SmokeFrameworkExamples

See this repository for examples of the Smoke Framework and the related Smoke* repositories in action.

Getting Started using Code Generation

The Smoke Framework provides a code generator that will generate a complete Swift Package Manager repository for a SmokeFramework-based service from a Swagger 2.0 specification file.

See the instructions in the code generator repository on how to get started.

Getting Started without Code Generation

These steps assume you have just created a new swift application using swift package init --type executable.

Step 1: Add the Smoke Framework dependency

The Smoke Framework uses the Swift Package Manager. To use the framework, add the following dependency to your Package.swift-

dependencies: [
    .package(url: "https://github.com/amzn/smoke-framework.git", from: "2.0.0")
]

.target(name: ..., dependencies: [
    ..., 
    .product(name: "SmokeOperationsHTTP1Server", package: "smoke-framework"),
]),

Step 2: Update the runtime dependency requirements of the application

If you attempt to compile the application, you will get the error

the product 'XXX' requires minimum platform version 10.12 for macos platform

This is because SmokeFramework projects have a minimum MacOS version dependency. To correct this there needs to be a couple of additions to to the Package.swift file.

Step 2a: Update the language version

Specify the language versions supported by the application-

targets: [
    ...
    ],
swiftLanguageVersions: [.v5]

Step 2b: Update the supported platforms

Specify the platforms supported by the application-

name: "XXX",
platforms: [
  .macOS(.v10_15), .iOS(.v10)
],
products: [

Step 2: Add a Context Type

An instance of the context type will be passed to each invocation of an operation that needs to be handled. This instance can be setup to be initialized per invocation or once for the application.

You will need to create this context type. There are no requirements for a type to be passed as a context. The following code shows an example of creating the context type-

public struct MyApplicationContext {
    let logger: Logger
    // TODO: Add properties to be accessed by the operation handlers
    
    public init(logger: Logger) {
        self.logger = logger
    }
}

Step 3: Add an Operation Function

The next step to using the Smoke Framework is to define one or more functions that will perform the operations that your application requires. The following code shows an example of such a function-

extension MyApplicationContext {
    func handleTheOperation(input: OperationInput) throws -> OperationOutput {
        return OperationOutput()
    }
}

This particular operation function accepts the input to the operation and is within an extension of the context (giving it access to any attributes or functions on this type) while returning the output from the operation.

For HTTP1, the operation input can conform to OperationHTTP1InputProtocol, which defines how the input type is constructed from the HTTP1 request. Similarly, the operation output can conform to OperationHTTP1OutputProtocol, which defines how to construct the HTTP1 response from the output type. Both must also conform to the Validatable protocol, giving the opportunity to validate any field constraints.

As an alternative, both operation input and output can conform to the Codable protocol if they are constructed from only one part of the HTTP1 request and response.

The Smoke Framework also supports additional built-in and custom operation function signatures. See the The Operation Function and Extension Points sections for more information.

Step 4: Add Handler Selection

After defining the required operation handlers, it is time to specify how they are selected for incoming requests.

The Smoke Framework provides the SmokeHTTP1HandlerSelector protocol to add handlers to a selector.

import SmokeOperationsHTTP1

public enum MyOperations: String, Hashable, CustomStringConvertible {
    case theOperation = "TheOperation"

    public var description: String {
        return rawValue
    }

    public var operationPath: String {
        switch self {
        case .theOperation:
            return "/theOperation"
        }
    }
}

public extension MyOperations {
    static func addToSmokeServer<SelectorType: SmokeHTTP1HandlerSelector>(selector: inout SelectorType)
            where SelectorType.ContextType == MyApplicationContext,
                  SelectorType.OperationIdentifer == MyOperations {
        
        let allowedErrorsForTheOperation: [(MyApplicationErrors, Int)] = [(.unknownResource, 404)]
        selector.addHandlerForOperationProvider(.theOperation, httpMethod: .POST,
                                                operationProvider: MyApplicationContext.handleTheOperation,
                                                allowedErrors: allowedErrorsForTheOperation)
    }
}

Each handler added requires the following parameters to be specified:

  • The operation to be added. This must be of a type conforming to OperationIdentity such as an enum.
    • The HTTP method that must be matched by the incoming request to select the handler.
    • The function to be invoked.
    • The errors that can be returned to the caller from this handler. The error type must also conform to CustomStringConvertible that returns the identity of the current error.
    • The location in the HTTP1 request to construct the operation input type from (only required if the input type conforms to Codable)
    • The location in the HTTP1 response that the output type represents (only required if the output type conforms to Codable)

Step 5: Setting up the Application Server

The final step is to setup an application as an operation server.

import Foundation
import SmokeOperationsHTTP1Server
import AsyncHTTPClient
import NIO
import SmokeHTTP1

struct MyPerInvocationContextInitializer: StandardJSONSmokeServerPerInvocationContextInitializer {
    typealias ContextType = MyApplicationContext
    typealias OperationIdentifer = MyOperations
    
    let serverName = "MyService"
    // specify the operations initializer
    let operationsInitializer: OperationsInitializerType = MyOperations.addToSmokeServer

    /**
     On application startup.
     */
    init(eventLoopGroup: EventLoopGroup) throws {
        // set up any of the application-wide context
    }

    /**
     On invocation.
    */
    public func getInvocationContext(
        invocationReporting: SmokeServerInvocationReporting<SmokeInvocationTraceContext>) -> MyApplicationContext {
        // create an invocation-specific context to be passed to an operation handler
        return MyApplicationContext(logger: invocationReporting.logger)
    }

    /**
     On application shutdown.
    */
    func onShutdown() throws {
        // shutdown anything before the application closes
    }
}

SmokeHTTP1Server.runAsOperationServer(MyPerInvocationContextInitializer.init)

You can now run the application and the server will start up on port 8080. The application will block in the SmokeHTTP1Server.runAsOperationServer call. When the server has been fully shutdown and has completed all requests, onShutdown will be called. In this function you can close/shutdown any clients or credentials that were created on application startup.

Step 6: Add Reporting Configuration (Optional)

An optional configuration step is to setup the reporting configuration for metrics emitted by the Smoke Framework. This involves overriding the default reportingConfiguration attribute on the initializer. For the metrics to be emitted, a swift-metrics backend - such as CloudWatchMetricsFactory - will need to be initialized.

...

struct MyPerInvocationContextInitializer: StandardJSONSmokeServerPerInvocationContextInitializer {
    typealias ContextType = MyApplicationContext
    typealias OperationIdentifer = MyOperations
    
    let reportingConfiguration: SmokeReportingConfiguration<OperationIdentifer>
    let serverName = "MyService"
    // specify the operations initializer
    let operationsInitializer: OperationsInitializerType = MyOperations.addToSmokeServer

    /**
     On application startup.
     */
    init(eventLoopGroup: EventLoopGroup) throws {
        // set up any of the application-wide context
        
        // for the server, only report the latency metrics
        // only report 5XX error counts for TheOperation (even if additional operations are added in the future)
        // only report 4XX error counts for operations other than TheOperation (as they are added in the future)
        self.reportingConfiguration = SmokeReportingConfiguration(
            successCounterMatchingRequests: .none,
            failure5XXCounterMatchingRequests: .onlyForOperations([.theOperation]),
            failure4XXCounterMatchingRequests: .exceptForOperations([.theOperation]),
            latencyTimerMatchingRequests: .all,
            serviceLatencyTimerMatchingRequests: .all,
            outwardServiceCallLatencyTimerMatchingRequests: .all,
            outwardServiceCallRetryWaitTimerMatchingRequests: .all)
    }

    ...
}

SmokeHTTP1Server.runAsOperationServer(MyPerInvocationContextInitializer.init)

Further Concepts

The Application Context

An instance of the application context type is created at application start-up and is passed to each invocation of an operation handler. The framework imposes no restrictions on this type and simply passes it through to the operation handlers. It is recommended that this context is immutable as it can potentially be passed to multiple handlers simultaneously. Otherwise, the context type is responsible for handling its own thread safety.

It is recommended that applications use a strongly typed context rather than a bag of stuff such as a Dictionary.

The Operation Delegate

The Operation Delegate handles specifics such as encoding and decoding requests to the handler's input and output.

The Smoke Framework provides the JSONPayloadHTTP1OperationDelegate implementation that expects a JSON encoded request body as the handler's input and returns the output as the JSON encoded response body.

Each addHandlerForOperation invocation can optionally accept an operation delegate to use when that handler is selected. This can be used when operations have specific encoding or decoding requirements. A default operation delegate is set up at server startup to be used for operations without a specific handler or when no handler matches a request.

The Trace Context

The JSONPayloadHTTP1OperationDelegate takes a generic parameter conforming to the HTTP1OperationTraceContext protocol. This protocol can be used to providing request-level tracing. The requirements for this protocol are defined here.

A default implementation - SmokeInvocationTraceContext - provides some basic tracing using request and response headers.

The Operation Function

Each handler provides a function to be invoked when the handler is selected. By default, the Smoke framework provides four function signatures declared on the Context Type that this function can conform to-

  • ((InputType) throws -> ()): Synchronous method with no output.
  • ((InputType) throws -> OutputType): Synchronous method with output.
  • ((InputType, (Swift.Error?) -> ()) throws -> ()): Asynchronous method with no output.
  • ((InputType, (Result<OutputType, Error>) -> ()) throws -> ()): Asynchronous method with output.

Due to Swift type inference, a handler can switch between these different signatures without changing the handler selector declaration - simply changing the function signature is sufficient.

The synchronous variants will return a response as soon as the function returns either with an empty body or the encoded return value. The asynchronous variants will return a response when the provided result handlers are called.

public protocol Validatable {
    func validate() throws
}

In all cases, the InputType and OutputType types must conform to the Validatable protocol. This protocol gives a type the opportunity to verify its fields - such as for string length, numeric range validation. The Smoke Framework will call validate on operation inputs before passing it to the handler and operation outputs after receiving from the handler-

  • If an operation input fails its validation call (by throwing an error), the framework will fail the operation with a 400 ValidationError response, indicating an error by the caller (the framework also logs this event at Info level).

  • If an operation output fails its validation call (by throwing an error), the framework will fail the operation with a 500 Internal Server Error, indicating an error by the service logic (the framework also logs this event at Error level).

    Additionally, the Smoke Framework provides the option to declare operation handlers outside the Context Type as standalone functions. The Context Type is passed in directly to these functions.

    func handleTheOperation(input: OperationInput, context: MyApplicationContext) throws -> OperationOutput {
        return OperationOutput()
    }

    Adding the handler selection is slightly different in this case-

    import SmokeOperationsHTTP1
    
    public func addOperations<SelectorType: SmokeHTTP1HandlerSelector>(selector: inout SelectorType)
            where SelectorType.ContextType == MyApplicationContext,
                  SelectorType.OperationIdentifer == MyOperations {
        
        let allowedErrorsForTheOperation: [(MyApplicationErrors, Int)] = [(.unknownResource, 404)]
        selector.addHandlerForOperation(.theOperation, httpMethod: .POST,
                                        operation: handleTheOperation,
                                        allowedErrors: allowedErrorsForTheOperation)
    }

The four function signatures are also available when using this style of operation handlers.

  • ((InputType, ContextType) throws -> ()): Synchronous method with no output.
  • ((InputType, ContextType) throws -> OutputType): Synchronous method with output.
  • ((InputType, ContextType, (Swift.Error?) -> ()) throws -> ()): Asynchronous method with no output.
  • ((InputType, ContextType, (Result<OutputType, Error>) -> ()) throws -> ()): Asynchronous method with output.

Error Handling

By default, any errors thrown from an operation handler will fail the operation and the framework will return a 500 Internal Server Error to the caller (the framework also logs this event at Error level). This behavior prevents any unintentional leakage of internal error information.

public typealias ErrorIdentifiableByDescription = Swift.Error & CustomStringConvertible
public typealias SmokeReturnableError = ErrorIdentifiableByDescription & Encodable

Errors can be explicitly encoded and returned to the caller by conforming to the Swift.Error, CustomStringConvertible and Encodable protocols and being specified under allowedErrors in the addHandlerForUri call setting up the operation handler. For example-

public enum MyError: Swift.Error {
    case theError(reason: String)
    
    enum CodingKeys: String, CodingKey {
        case reason = "Reason"
    }
}

extension MyError: Encodable {
    public func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        
        switch self {
        case .theError(reason: let reason):
            try container.encode(reason, forKey: .reason)
        }
    }
}

extension MyError: CustomStringConvertible {
    public var description: String {
        return "TheError"
    }
}

When such an error is returned from an operation handler-

  • A response is returned to the caller with the HTTP code specified in the allowedErrors entry with a payload of the error encoded according to the Encodable protocol.
  • In addition, the provided error identity of the error will be specified in the __type field of the returned payload.
  • Comparison between the error specified in the allowedErrors list and the error thrown from the operation handler is a string comparison between the respective error identities. This is to allow equivalent errors of differing type (such as code generated errors from different models) to be handled as the same error.
  • For the built-in asynchronous operation functions, errors can either be thrown synchronously from the function itself or passed asynchronously to the result handler. Either way, the operation will fail according to the type of error thrown or passed. This is to avoid functions having to catch synchronous errors (such as in setup) only to pass them to the result handler.

Testing

The Smoke Framework has been designed to make testing of operation handlers straightforward. It is recommended that operation handlers are pure functions (where its return value is determined by the function's logic and input values). In this case, the function can be called in unit tests with appropriately constructed input and context instances.

It is recommended that the application-specific context be used to vary behavior between release and testing executions - such as mocking service clients, random number generators, etc. In general this will create more maintainable tests by keeping all the testing logic in the testing function.

If you want to run all test cases in Smoke Framework, please open command line and go to smoke-framework (root) directory, run swift test and then you should be able to see test cases result.

Extension Points

The Smoke Framework is designed to be extensible beyond its current functionality-

  • JSONPayloadHTTP1OperationDelegate provides basic JSON payload encoding and decoding. Instead, the HTTP1OperationDelegate protocol can be used to create a delegate that provides alternative payload encoding and decoding. Instances of this protocol are given the entire HttpRequestHead and request body when decoding the input and encoding the output for situations when these are required.
  • StandardSmokeHTTP1HandlerSelector provides a handler selector that compares the HTTP URI and verb to select a handler. Instead, the SmokeHTTP1HandlerSelector protocol can be used to create a selector that can use any property from the HTTPRequestHead (such as headers) to select a handler.
  • Even if StandardSmokeHTTP1HandlerSelector does fit your requirements, it can be extended to support additional function signatures. See the built-in function signatures (one can be found in OperationHandler+nonblockingWithInputWithOutput.swift) for examples of this.
  • The Smoke Framework currently supports HTTP1 but can be extended to additional protocols while using the same operation handlers if needed. The initializers of OperationHandler provide a protocol-agnostic layer - as an example [1] - which can be used by a protocol-specific layer - such as [2] for HTTP1 - to abstract protocol-specific handling for the different operation types.

[1] https://github.com/amzn/smoke-framework/blob/master/Sources/SmokeOperations/OperationHandler%2BblockingWithInputWithOutput.swift

[2] https://github.com/amzn/smoke-framework/blob/master/Sources/SmokeOperationsHTTP1/SmokeHTTP1HandlerSelector%2BblockingWithInputWithOutput.swift

License

This library is licensed under the Apache 2.0 License.

Comments
  • Add integration/pull request CI testing for Smoke Framework

    Add integration/pull request CI testing for Smoke Framework

    Description

    Add integration tests for the framework

    Exit criteria

    The integration tests should-

    • pull the latest version of the code or the pull request being submitted
    • build the code, run tests and SwiftLint
    • Build the change into an example application, make sure application compiles and starts up
    • Hit an endpoint on the sample application and verify expected result was returned.
    opened by tachyonics 8
  • Add missing SmokeHTTP1 dependency from SmokeOperationsHTTP1Tests.

    Add missing SmokeHTTP1 dependency from SmokeOperationsHTTP1Tests.

    Issue #, if available: #77

    Description of changes: Identified by @Davidde94 as causing a non-deterministic compilation failure. Added dependency as suggested.

    By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

    opened by tachyonics 3
  • Missing `SmokeHTTP1` dependency from `SmokeOperationsHTTP1Tests`

    Missing `SmokeHTTP1` dependency from `SmokeOperationsHTTP1Tests`

    Non-deterministic, it depends how quickly SPM manages to get to compiling SmokeHTTP. Fix should be really easy, just add the dependency :)

    Build log below:

    [803/815] Merging module _SmokeOperationsHTTP1Concurrency
    [804/815] Merging module SmokeHTTP1
    [805/817] Compiling SmokeOperationsHTTP1Server HTTP1OperationTraceContext.swift
    /workspace/.logs/**/*.log/5DAB444C-FE1F-49B1-8186-3CEDB8A2AA1D/repos/smoke-framework/Tests/SmokeOperationsHTTP1Tests/SmokeOperationsHTTP1AsyncTests.swift:21:8: error: no such module 'SmokeHTTP1'
    import SmokeHTTP1
           ^
    [807/828] Compiling SmokeOperationsHTTP1Server JSONPayloadHTTP1OperationDelegate.swift
    /workspace/.logs/**/*.log/5DAB444C-FE1F-49B1-8186-3CEDB8A2AA1D/repos/smoke-framework/Tests/SmokeOperationsHTTP1Tests/SmokeOperationsHTTP1AsyncTests.swift:21:8: error: no such module 'SmokeHTTP1'
    import SmokeHTTP1
           ^
    [810/828] Compiling SmokeOperationsHTTP1Server HTTP1RequestInvocationContext.swift
    [811/828] Compiling SmokeOperationsHTTP1Server SmokeServerPerInvocationContextInitializer.swift
    [813/828] Compiling SmokeOperationsHTTP1Server SmokeInvocationTraceContext.swift
    [814/828] Compiling SmokeOperationsHTTP1Server SmokeHTTP1Server+runAsOperationServer.swift
    /workspace/.logs/**/*.log/5DAB444C-FE1F-49B1-8186-3CEDB8A2AA1D/repos/smoke-framework/Tests/SmokeOperationsHTTP1Tests/SmokeOperationsHTTP1AsyncTests.swift:21:8: error: no such module 'SmokeHTTP1'
    import SmokeHTTP1
           ^
    [817/829] Compiling SmokeOperationsHTTP1Server SmokeServerStaticContextInitializer.swift
    [818/829] Compiling SmokeOperationsHTTP1Server SmokeServerInvocationReporting.swift
    [819/829] Compiling SmokeOperationsHTTP1Server SmokeServerInvocationContext+HTTP1RequestInvocationContext.swift
    /workspace/.logs/**/*.log/5DAB444C-FE1F-49B1-8186-3CEDB8A2AA1D/repos/smoke-framework/Tests/SmokeOperationsHTTP1Tests/SmokeOperationsHTTP1AsyncTests.swift:21:8: error: no such module 'SmokeHTTP1'
    import SmokeHTTP1
           ^
    Command failed reason=exit, status=1
    
    opened by Davidde94 3
  • tests don't compile on Linux

    tests don't compile on Linux

    when trying to compile the tests on master (on Linux), I get:

    Compile Swift Module 'SmokeFrameworkPackageTests' (1 sources)
    /tmp/.nio-release-tools_3y9rpD/smoke-framework/Tests/LinuxMain.swift:5:14: error: use of unresolved identifier 'SmokeOperationsHTTP1AsyncTests'
        testCase(SmokeOperationsHTTP1AsyncTests.allTests),
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    <unknown>:0: note: did you mean 'SmokeOperationsAsyncTests'?
    /tmp/.nio-release-tools_3y9rpD/smoke-framework/Tests/LinuxMain.swift:6:14: error: use of unresolved identifier 'SmokeOperationsHTTP1SyncTests'
        testCase(SmokeOperationsHTTP1SyncTests.allTests),
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    <unknown>:0: note: did you mean 'SmokeOperationsSyncTests'?
    <unknown>:0: note: did you mean 'SmokeOperationsAsyncTests'?
    

    with this commit (current master):

    $ git rev-parse HEAD
    c005cffc2def1e10ddb7f7d0d4162cd99747ae05
    
    opened by weissi 3
  • Remove swift 5.1 support

    Remove swift 5.1 support

    Issue #, if available:

    Description of changes:

    1. Remove swift 5.1 support
    2. Add missing target dependency.
    3. Fix spelling of detach.

    By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

    opened by tachyonics 2
  • Consider depending on Swift Metrics 2.x (whilst still allowing 1.x)

    Consider depending on Swift Metrics 2.x (whilst still allowing 1.x)

    Swift Metrics 2.0 just got released. It is almost completely compatible with Swift Metrics 1.x unless you exhaustively switch on the TimeUnit enum. I would highly recommend depending on swift-metrics like the following:

    // swift-metrics 1.x and 2.x are almost API compatible, so most clients should use
    .package(url: "https://github.com/apple/swift-metrics.git", "1.0.0" ..< "3.0.0"),
    

    alternatively, from: "2.0.0" will also work but may in the interim cause compatibility issues with packages that specify from: "1.0.0".

    If at all possible, this should be done before tagging the next release here. If using "1.0.0" ..< "3.0.0" this isn't even a SemVer major change because 1.x versions are still accepted.

    opened by weissi 2
  • Smoke should close the Channel if it receives an error in the last ChannelHandler

    Smoke should close the Channel if it receives an error in the last ChannelHandler

    In SwiftNIO it's generally a good idea that on errorCaught, the Channel should be closed to prevent leaking network connections that are in some error states. In Smoke this should be added to the HTTP1ChannelInboundHandler and the same for smoke-http-client wants that too.

    Why? Generally, ChannelHandlers fire errors in cases where they don't know how to recover themselves. If another, later ChannelHandler knows how to recover, that ChannelHandler would consume the error. In other words: If an error reaches the end of the pipeline, nobody knew how to handle that error and closing the Channel is a good default.

    This has always been true in SwiftNIO but in NIO 2 this will become especially important because ByteToMessageDecoders (and the HTTP decoders) won't close the connections themselves anymore. Why is that? If the decoders themselves close the connection, then there's no way for the user to opt out.

    The code to implement this is very straightforward:

    public func errorCaught(ctx: ChannelHandlerContext, error: Error) {
        switch error {
        case let e as SomeErrorTypeIKnowHowToHandle where e.someCondition == expectedValue:
            // handle error
        case let e as SomeOtherErrorIKnowHowToHandle:
            // handle that error
        default:
            // log error?
            ctx.close(promise: nil)
        }
    }
    
    opened by weissi 2
  • Improve shutdown behaviour

    Improve shutdown behaviour

    Description

    Determine the best mechanism to wait until a service is shutting down and provide a hook to easily shutdown clients etc that where initialised at the start of the application.

    Currently we are waiting on the current runloop which may not be the best mechanism to wait until a service is shutting down and providing an opportunity to close clients. It looks like Kitura uses a DispatchGroup[2] to wait until the server is shutting down.

    Exit criteria

    • Investigate the best mechanism for waiting for service shutdown and providing an opportunity for applications to shut down clients etc
    • Provide implementation for this new shutdown behaviour
    • Update documentation to include this behaviour

    [1] https://github.com/amzn/smoke-framework/blob/master/Sources/SmokeOperationsHTTP1/SmokeHTTP1Server%2BstartAsOperationServer.swift#L54 [2] https://github.com/IBM-Swift/Kitura-NIO/blob/5d9bd67596881876d8a0843b41b3bff00e5c9059/Sources/KituraNet/ListenerGroup.swift

    opened by tachyonics 2
  • Restructure HTTP1-specific code from SmokeOperations package

    Restructure HTTP1-specific code from SmokeOperations package

    Description

    Restructure HTTP1-specific code from SmokeOperations library to a new SmokeOperationsHTTP1 library to provide a clear separation between protocol-specific and protocol-agnostic code. This makes it clearer that HTTP1 is just one possible protocol that can be used with the core SmokeOperations library.

    Description of changes: No code changes apart from making some types public.

    This is a breaking change as it will require applications to import SmokeOperationsHTTP1 rather than SmokeOperations for HTTP1-specific types.

    Testing

    swift build && swift test

    By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

    opened by tachyonics 2
  • Tutorial / basic server

    Tutorial / basic server

    It would be super useful to add a code example or a tutorial for creating and building a basic project. For example, a web server that returns books on a GET request and creates a book on a POST request. 😄

    opened by ilyagru 2
  • Swift nio 2 dependencies

    Swift nio 2 dependencies

    Issue #, if available: #29

    Description of changes: Follow the SwiftNIO migration guide[1].

    [1] https://github.com/apple/swift-nio/blob/master/docs/migration-guide-NIO1-to-NIO2.md

    By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

    opened by tachyonics 1
  • Add discussion on the Context Type.

    Add discussion on the Context Type.

    Issue #, if available:

    Description of changes: Add discussion on the Context Type, its usage and practices.

    By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

    opened by tachyonics 0
  • Add operation identifier to invocation context; allow known errors to be returned from Smoke operation

    Add operation identifier to invocation context; allow known errors to be returned from Smoke operation

    Issue #, if available:

    Description of changes:

    • Add operation identifier to the parameters sent for invocation context initialization.
    • Allow known errors to be returned as typed errors from Smoke operations even when such error is not specified in the operation's allowed errors. Clients can opt-in error types by implementing the SmokeKnownError to specify conformance of errors to known types. For now, the only type available is unrecognizedErrorFromExternalCall.

    By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

    opened by pbthif 0
  • Incorporate swift-service-lifecycle

    Incorporate swift-service-lifecycle

    Incorporate swift-service-lifecycle[1] to standardise the startup and shutdown mechanisms for smoke-framework based applications.

    [1] https://github.com/swift-server/swift-service-lifecycle

    opened by tachyonics 0
  • Package.swift does not contain all dependencies

    Package.swift does not contain all dependencies

    Some versions of swift package manager react badly to missing dependencies in the swift package file.

    For example -

    SmokeHTTP1 uses SmokeOperations (here https://github.com/amzn/smoke-framework/blob/main/Sources/SmokeHTTP1/ChannelHTTP1ResponseHandler.swift#L21)

    but there is no declared dependency (here https://github.com/amzn/smoke-framework/blob/db1332849a16575cb71426ccfbc2065d2f0c3352/Package.swift#L59-L65)

    opened by PeterAdams-A 2
Releases(2.15.0)
  • 2.15.0(Sep 6, 2022)

    This release of SmokeFramework provides compatibility with Swift 5.4, Swift 5.5, Swift 5.6 using SwiftNIO 2.x.

    1. Provide more descriptive messages from decoding errors (#110)
    Source code(tar.gz)
    Source code(zip)
  • 2.14.2(Aug 31, 2022)

    This release of SmokeFramework provides compatibility with Swift 5.4, Swift 5.5, Swift 5.6 using SwiftNIO 2.x.

    1. Don't log input decoding or validation failure as error or warning (#109)
    Source code(tar.gz)
    Source code(zip)
  • 2.14.1(Aug 31, 2022)

    This release of SmokeFramework provides compatibility with Swift 5.4, Swift 5.5, Swift 5.6 using SwiftNIO 2.x.

    1. Split out status.reasonPhrase and status.code when logging responses (#108)
    Source code(tar.gz)
    Source code(zip)
  • 2.14.0(Aug 24, 2022)

    This release of SmokeFramework provides compatibility with Swift 5.4, Swift 5.5, Swift 5.6 using SwiftNIO 2.x.

    1. Conform SmokeServerInvocationReporting to HTTPClientInvocationAttributes (#107)
    Source code(tar.gz)
    Source code(zip)
  • 2.13.4(Aug 24, 2022)

    This release of SmokeFramework provides compatibility with Swift 5.4, Swift 5.5, Swift 5.6 using SwiftNIO 2.x.

    1. Log body data at info level for input to and output from incoming requests (#106)
    Source code(tar.gz)
    Source code(zip)
  • 2.13.3(Jul 21, 2022)

    This release of SmokeFramework provides compatibility with Swift 5.4, Swift 5.5, Swift 5.6 using SwiftNIO 2.x.

    1. Backport logging changes (#104)
    2. Make SmokeInwardsRequestContext thread safe (#105)
    Source code(tar.gz)
    Source code(zip)
  • 2.13.2(Jun 25, 2022)

    This release of SmokeFramework provides compatibility with Swift 5.4, Swift 5.5, Swift 5.6 using SwiftNIO 2.x.

    1. Use checked rather than unsafe continuations. (#100)
    Source code(tar.gz)
    Source code(zip)
  • 2.13.1(Mar 28, 2022)

    This release of SmokeFramework provides compatibility with Swift 5.4, Swift 5.5, Swift 5.6 using SwiftNIO 2.x.

    1. Use correct conformance for all supported compiler versions, fixing warnings under Swift 5.6 (#96)
    2. Update CI for Swift 5.6, remove 5.3 (#96)
    Source code(tar.gz)
    Source code(zip)
  • 2.13.0(Jan 14, 2022)

    This release of SmokeFramework provides compatibility with Swift 5.3, Swift 5.4, Swift 5.5 using SwiftNIO 2.x.

    1. Support async application initialisation and shutdown (#93)
    Source code(tar.gz)
    Source code(zip)
  • 2.12.0(Nov 3, 2021)

    This release of SmokeFramework provides compatibility with Swift 5.3, Swift 5.4, Swift 5.5 using SwiftNIO 2.x.

    1. Remove Swift 5.2 from CI Tests. (#91)
    2. Support async operation handlers on older Apple OSs. (#91)
    Source code(tar.gz)
    Source code(zip)
  • 2.11.2(Oct 29, 2021)

    This release of SmokeFramework provides compatibility with Swift 5.2, Swift 5.3, Swift 5.4, Swift 5.5 using SwiftNIO 2.x.

    1. Migrate to Github actions for CI. (#87)
    2. Allowing shutdown on a list of signals (#88)
    3. Add the ability to create metrics for specific HTTP error status codes (#89)
    Source code(tar.gz)
    Source code(zip)
  • 2.11.0(Sep 23, 2021)

    This release of SmokeFramework provides compatibility with Swift 5.2, Swift 5.3, Swift 5.4, Swift 5.5 using SwiftNIO 2.x.

    1. Update CI and README for Swift 5.5 (#86)
    2. Move async function support into non-unscored packages (#86)
    3. Re-export non-unscored packages in unscored packages to avoid breaking anyone who imported the unscored package. (#86)

    Note: Support for async functions as operation handlers require Swift 5.5 and will be unavailable otherwise. Additionally if compiling on a Mac computer, these APIs require the yet-to-be-released macOS 12 Monterey along with a yet-to-be-released version of Xcode.

    Source code(tar.gz)
    Source code(zip)
  • 2.10.1(Jul 2, 2021)

    This release of SmokeFramework provides compatibility with Swift 5.2, Swift 5.3 and Swift 5.4 using SwiftNIO 2.x.

    1. Clean up api availability on Apple platforms. Remove XCode Beta 1 workaround. (#82)
    Source code(tar.gz)
    Source code(zip)
  • 2.10.0(Jun 22, 2021)

    This release of SmokeFramework provides compatibility with Swift 5.2, Swift 5.3 and Swift 5.4 using SwiftNIO 2.x.

    1. Add addHandlerForOperationProvider handler overrides for EventLoopFuture-returning operations. (#81)
    2. Fix incorrect function parameter documentation. (#81)
    Source code(tar.gz)
    Source code(zip)
  • 2.9.1(Jun 9, 2021)

    This release of SmokeFramework provides compatibility with Swift 5.2, Swift 5.3 and Swift 5.4 using SwiftNIO 2.x.

    1. Add missing SmokeHTTP1 dependency from SmokeOperationsHTTP1Tests (#78)
    2. Remove package manifest and CI for Swift 5.1 and Ubuntu 16.04. (#79)
    3. Add workaround for XCode 13 Beta 1. (#80)
    Source code(tar.gz)
    Source code(zip)
  • 2.9.0(Apr 29, 2021)

    This release of SmokeFramework provides compatibility with Swift 5.1, Swift 5.2, Swift 5.3 and Swift 5.4 using SwiftNIO 2.x.

    1. Streamline the standard initialisation path (#75)
    2. Add CI for 5.4. Adopt latest async/await renames. (#76)
    3. Update README to by default create operation handlers within extensions of the context type. (#73)
    Source code(tar.gz)
    Source code(zip)
  • 2.8.0(Apr 13, 2021)

    This release of SmokeFramework provides compatibility with Swift 5.1, Swift 5.2 and Swift 5.3 using SwiftNIO 2.x.

    1. Add initial/experimental async/await support. (#37)

    Note: Async/await support is currently experimental and requires a recent development (nightly) snapshot[1] of the Swift toolchain; the added APIs should not be considered stable and no guarantees are provided about them.

    To use these APIs import _SmokeOperationsHTTP1Concurrency into the application's Sources/<BaseName>OperationsHTTP1/<BaseName>OperationsHanderSelector.swift file.

    [1] https://hub.docker.com/r/swiftlang/swift

    Source code(tar.gz)
    Source code(zip)
  • 2.7.0(Mar 26, 2021)

    This release of SmokeFramework provides compatibility with Swift 5.1, Swift 5.2 and Swift 5.3 using SwiftNIO 2.x.

    1. Fix documentation. (#69)
    2. Add addHandlerForOperationProvider functions to SmokeHTTP1HandlerSelector. (#70)
    Source code(tar.gz)
    Source code(zip)
  • 2.6.0(Feb 24, 2021)

    This release of SmokeFramework provides compatibility with Swift 5.1, Swift 5.2 and Swift 5.3 using SwiftNIO 2.x.

    1. Report request latency, broken down into time for service calls and waits for retries. (#68)
    2. Optionally emit three additional request metrics (#68) i. serviceLatencyTimer: Metrics.Timer ii. outwardsServiceCallLatencySumTimer: Metrics.Timer iii. outwardsServiceCallRetryWaitSumTimer: Metrics.Timer
    3. Fix an issue where the request metrics were not actually emitted (#68)
    Source code(tar.gz)
    Source code(zip)
  • 2.5.0(Jan 27, 2021)

    This release of SmokeFramework provides compatibility with Swift 5.1, Swift 5.2 and Swift 5.3 using SwiftNIO 2.x.

    1. Use the same event loop group for the initializer and server if the server is creating new threads anyway. (#67)
    2. Pass the event loop to the DelegatedInvocationReporting instance. (#67)
    Source code(tar.gz)
    Source code(zip)
  • 2.4.0(Jan 20, 2021)

    This release of SmokeFramework provides compatibility with Swift 5.1, Swift 5.2 and Swift 5.3 using SwiftNIO 2.x.

    1. Expose the request's eventLoop in SmokeServerInvocationReporting (#66)
    Source code(tar.gz)
    Source code(zip)
  • 2.3.2(Jan 12, 2021)

    This release of SmokeFramework provides compatibility with Swift 5.1, Swift 5.2 and Swift 5.3 using SwiftNIO 2.x.

    1. Remove redundant same-type constraint. (#65)
    Source code(tar.gz)
    Source code(zip)
  • 2.3.1(Nov 23, 2020)

    This release of SmokeFramework provides compatibility with Swift 5.1, Swift 5.2 and Swift 5.3 using SwiftNIO 2.x.

    1. Remove dangling import statements for SmokeOperations from the SmokeHTTP1 (#63)
    2. Remove support for Swift 5.0. Add CI verification of Swift 5.3. (#64)
    Source code(tar.gz)
    Source code(zip)
  • 2.3.0(Jul 21, 2020)

    This release of SmokeFramework provides compatibility with Swift 5.0, Swift 5.1 and Swift 5.2 using SwiftNIO 2.x.

    1. Add SmokeHTTP1Server.runAsOperationServer overloads that take a factory with an EventLoopGroup input. (#61)
    Source code(tar.gz)
    Source code(zip)
  • 2.2.0(Jul 2, 2020)

    This release of SmokeFramework provides compatibility with Swift 5.0, Swift 5.1 and Swift 5.2 using SwiftNIO 2.x.

    1. Move SmokeInvocationTraceContext into SmokeOperationsHTTP1 library (#60)
    Source code(tar.gz)
    Source code(zip)
  • 2.1.1(May 15, 2020)

    This release of SmokeFramework provides compatibility with Swift 5.0, Swift 5.1 and Swift 5.2 using SwiftNIO 2.x.

    1. Log all non-500 responses at info rather than error which could pollute logs with false-positive errors. (#58 / #59)
    Source code(tar.gz)
    Source code(zip)
  • 2.1.0(May 13, 2020)

    This release of SmokeFramework provides compatibility with Swift 5.0, Swift 5.1 and Swift 5.2 using SwiftNIO 2.x.

    1. Add handler signatures that return an EventLoopFuture. (#57)
    Source code(tar.gz)
    Source code(zip)
  • 2.0.0(May 5, 2020)

    This release of SmokeFramework provides compatibility with Swift 5.0, Swift 5.1 and Swift 5.2 using SwiftNIO 2.x.

    1. Migrate to swift-nio 2.x.
    2. Adopt swift-log for logging
    3. Adopt swift-metrics for metrics.
    4. Provide extension points for basic tracing.
    Source code(tar.gz)
    Source code(zip)
  • 2.0.0-rc.1(Apr 28, 2020)

    This release of SmokeFramework provides compatibility with Swift 5.0, Swift 5.1 and Swift 5.2 using SwiftNIO 2.x.

    1. Close ChannelHandler on error. (#55)

    General release notes from SmokeFramework 2.x-

    1. Migrate to swift-nio 2.x.
    2. Adopt swift-log for logging
    3. Adopt swift-metrics for metrics.
    4. Provide extension points for basic tracing.
    Source code(tar.gz)
    Source code(zip)
  • 2.0.0-beta.1(Apr 12, 2020)

    This release of SmokeFramework provides compatibility with Swift 5.0, Swift 5.1 and Swift 5.2 using SwiftNIO 2.x.

    No changes from 2.0.0-alpha.7.

    General release notes from SmokeFramework 2.x-

    1. Migrate to swift-nio 2.x.
    2. Adopt swift-log for logging
    3. Adopt swift-metrics for metrics.
    4. Provide extension points for basic tracing.
    Source code(tar.gz)
    Source code(zip)
Owner
Amazon
Amazon
Tiny http server engine written in Swift programming language.

What is Swifter? Tiny http server engine written in Swift programming language. Branches * stable - lands on CocoaPods and others. Supports the latest

null 3.6k Jan 5, 2023
Server-side Swift. The Perfect core toolset and framework for Swift Developers. (For mobile back-end development, website and API development, and more…)

Perfect: Server-Side Swift 简体中文 Perfect: Server-Side Swift Perfect is a complete and powerful toolbox, framework, and application server for Linux, iO

PerfectlySoft Inc. 13.9k Dec 29, 2022
💧 A server-side Swift HTTP web framework.

Vapor is an HTTP web framework for Swift. It provides a beautifully expressive and easy-to-use foundation for your next website, API, or cloud project

Vapor 22.4k Jan 3, 2023
Reliable Server Side Swift ✭ Make Apache great again!

mod_swift mod_swift is a technology demo which shows how to write native modules for the Apache Web Server in the Swift 3 programming language. The de

The ApacheExpress Alliance 174 Oct 22, 2022
Swift Express is a simple, yet unopinionated web application server written in Swift

Documentation <h5 align="right"><a href="http://demo.swiftexpress.io/">Live ?? server running Demo <img src="https://cdn0.iconfinder.com/data/icons/

Crossroad Labs 850 Dec 2, 2022
Swift backend / server framework (Pure Swift, Supports Linux)

NetworkObjects NetworkObjects is a #PureSwift backend. This framework compiles for OS X, iOS and Linux and serves as the foundation for building power

Alsey Coleman Miller 258 Oct 6, 2022
libuv base Swift web HTTP server framework

Notice Trevi now open a Trevi Community. Yoseob/Trevi project split up into respective Trevi, lime, middlewares and sys packages at our community. If

leeyoseob 46 Jan 29, 2022
A Swift web framework and HTTP server.

A Swift Web Framework and HTTP Server Summary Kitura is a web framework and web server that is created for web services written in Swift. For more inf

Kitura 7.6k Dec 27, 2022
Simple server APIs in Swift

Simple server APIs in Swift

null 4 Apr 25, 2022
Swift HTTP server using the pre-fork worker model

Curassow Curassow is a Swift Nest HTTP Server. It uses the pre-fork worker model and it's similar to Python's Gunicorn and Ruby's Unicorn. It exposes

Kyle Fuller Archive 397 Oct 30, 2022
Lightweight library for web server applications in Swift on macOS and Linux powered by coroutines.

Why Zewo? • Support • Community • Contributing Zewo Zewo is a lightweight library for web applications in Swift. What sets Zewo apart? Zewo is not a w

Zewo 1.9k Dec 22, 2022
High Performance (nearly)100% Swift Web server supporting dynamic content.

Dynamo - Dynamic Swift Web Server Starting this project the intention was to code the simplest possible Web Server entirely in Swift. Unfortunately I

John Holdsworth 68 Jul 25, 2022
Super lightweight async HTTP server library in pure Swift runs in iOS / MacOS / Linux

Embassy Super lightweight async HTTP server in pure Swift. Please read: Embedded web server for iOS UI testing. See also: Our lightweight web framewor

Envoy 540 Dec 15, 2022
PillowTalk - An iOS & SwiftUI server monitor tool for linux based machines using remote proc file system with script execution.

An iOS & SwiftUI server monitor tool for linux based machines using remote proc file system with script execution.

Lakr Aream 416 Dec 16, 2022
A small, lightweight, embeddable HTTP server for Mac OS X or iOS applications

CocoaHTTPServer CocoaHTTPServer is a small, lightweight, embeddable HTTP server for Mac OS X or iOS applications. Sometimes developers need an embedde

Robbie Hanson 5.5k Jan 7, 2023
GCDWebServer is a modern and lightweight GCD based HTTP 1.1 server designed to be embedded in iOS, macOS & tvOS apps.

GCDWebServer is a modern and lightweight GCD based HTTP 1.1 server designed to be embedded in iOS, macOS & tvOS apps. It was written from scr

Pierre-Olivier Latour 6.3k Dec 27, 2022
iOS Tweak to redirect Discord API calls to a Fosscord server.

FosscordTweak iOS Tweak to redirect Discord API calls to a Fosscord server. Installation Manual Download .deb file from release and install on jailbro

null 8 May 16, 2022
A dockerized microservice written in Swift using Vapor.

price-calculation-service-swift This is an example project for a university project. It uses Vapor to serve a microservice written in Swift. The point

Fabian Geistert 1 Aug 23, 2022
A minimal, fast and unopinionated web framework for Swift

![Fire Image] (http://i.imgur.com/1qR6Nl4.png) Blackfire An extremely fast Swift web framework ?? Getting Started If you're familiar with express.js t

Elliott Minns 908 Dec 2, 2022