Swiftpack.co - Package - amzn/smoke-http

Build - Master Branch Linux Swift 5.0 Compatible Swift 5.1 Compatible Join the Smoke Server Side community on gitter Apache 2


SmokeHTTP contains the library SmokeHTTPClient which will allow someone building a specific client that requires unique use-cases for HTTP parameters to utilize a generic HTTPClient that allows the user to implement their own delegates that handles client-specific HTTP logic.

The benefit of this package is to consolidate all HTTPClient logic into one location, while other clients are built to utilize this client while defining their own specific delegates.


To use SmokeHTTPClient, a user can instantiate an HTTPClient in the constructor of their specific client with instantiated delegates (HTTPClientDelegate, HTTPClientChannelInboundHandlerDelegate) that are defined by the client-specific logic.

Getting Started

Step 1: Add the SmokeHTTP dependency

SmokeHTTP 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-http.git", from: "1.0.0")

    name: ...,
    dependencies: [..., "SmokeHTTPClient"]),

Step 2: Construct a HTTPClient

Construct a HTTPClient using the following code-

import SmokeHTTPClient

let httpClient = HTTPClient(endpointHostName: endpointHostName,
                            endpointPort: endpointPort,
                            contentType: contentType,
                            clientDelegate: clientDelegate,
                            connectionTimeoutSeconds: connectionTimeoutSeconds)

where clientDelegate conforms to the HTTPClientDelegate protocol.


This library is licensed under the Apache 2.0 License.


Stars: 42

Used By

Total: 0


Alpha 7 release for SmokeHTTP 2 - 2020-03-13 21:36:19

This release of SmokeHTTP provides compatibility with Swift 5.0 and Swift 5.1 using SwiftNIO 2.x.

  1. Use https://github.com/swift-server/async-http-client (#42)

Alpha 6 release for SmokeHTTP 2 - 2020-03-11 18:47:12

This release of SmokeHTTP provides compatibility with Swift 5.0 and Swift 5.1 using SwiftNIO 2.x.

  1. Provide an outgoingRequestId as Logger metadata to track the same invocation to a client (#53)

Alpha 5 release for SmokeHTTP 2 - 2020-03-10 20:04:12

This release of SmokeHTTP provides compatibility with Swift 5.0 and Swift 5.1 using SwiftNIO 2.x.

  1. Relax version requirements for swift-metrics. (#49)
  2. Add HTTPClientCoreInvocationReporting protocol and the MockCoreInvocationReporting (#52)

Alpha 4 release for SmokeHTTP 2 - 2020-03-04 03:39:41

  1. Visibility fix.
  2. Use valid semantic version.

Alpha 4 release for SmokeHTTP 2 - 2020-02-21 20:05:20

Visibility fix.

Alpha 3 release for SmokeHTTP 2 - 2020-02-20 00:56:12

  1. Add a MockInvocationTraceContext (#45)

Alpha 2 release for SmokeHTTP 2 - 2020-02-19 20:51:18

  1. Downstream service call tracing (#43)

Alpha 1 release for SmokeHTTP 2 - 2019-11-06 23:45:42

  1. Adopt SwiftLog 1, passing the logger explicitly (#31)
  2. Adopt SwiftMetrics 1 and record invocation metrics (#32)
  3. Adopt Swift.Result rather than our own Result types. (#29)
  4. Expose the http response code when throwing client errors (#33)
  5. Move SwiftNIO dependency to major version 2 (#35)
  6. Remove compatibility for Swift versions prior to 5 (#28)
  7. Client waits during connecting (#25)

Remove compiler warnings under Swift 5.x - 2019-10-01 17:46:37

Remove compiler warnings under Swift 5.x

First official release of SmokeHTTP - 2019-04-04 15:57:49

This release of SmokeHTTP provides compatibility with Swift 4.1 and Swift 4.2 using SwiftNIO 1.x.

Handle response more efficiently - 2019-04-02 00:25:19

Implement a number of internal fixes to be more efficient in memory usage, including using NIOFoundationCompat to convert directly from a ByteBuffer to Foundation.Data when receiving the response in HTTPClient.

Add a key transform strategy for encoding and decoding shapes. - 2019-03-26 22:56:55

Add a key transform strategy for encoding and decoding shapes with a passthrough option, an option to capitalise and de-capitalise the first character and a custom transform. This is enable use cases where there is a known mapping from the Codable instance to the serialised form that cannot be fully expressed as CodingKeys (the mapping is different in different circumstances.

Fix crash on Linux branch of getRetryInterval() - 2019-03-13 18:00:09

Fix crash on Linux branch of getRetryInterval().

Fixed a crash in client retry logic - 2019-03-12 21:07:27

Fixed for a fatal error when the retry configuration as 0 as the upper bound retry duration.

Fixed two issues with exponential retries. - 2019-02-26 01:00:32

  • Fixed an issue where async retries where both initiating a retry request and calling the completion handler
  • Fixed an issue where retry intervals where not being calculated correctly.

Add support for exponential backoff retries in HTTPClient - 2019-02-12 17:24:36

Added entry points to HTTPClient that will automatically handle request retries with exponential backoff-

  • HTTPClient.executeSyncRetriableWithOutput()
  • HTTPClient.executeSyncRetriableWithoutOutput()
  • HTTPClient.executeAsyncRetriableWithOutput()
  • HTTPClient.executeAsyncRetriableWithoutOutput()

Note: This is also a release-candidate for 1.0.0.

Another Internal refactor of HTTPPathDecoder - 2019-01-24 01:25:04

Move logic to get a Shape related to a template. This allows for cleaner determination if a http path conforms to a template.

Internal refactor of HTTPPathDecoder - 2019-01-04 15:18:46

Allow higher level components to decode a path into a Shape seperate to decoding it into a Swift type.

More Coders and HTTPClient improvements - 2018-12-19 20:00:12

This release is moving the library closer to finalized APIs for version 1.0. It has some breaking changes-

  • The execute*WithOutput APIs of HTTPClient now produce an instance conforming to HTTPResponseOutputProtocol. This is analogous to the input type HTTPRequestInputProtocol for these methods and provides access to decoded headers from the response.
  • The HTTPClientDelegate.getTLSConfiguration() function now returns an optional TLSConfiguration. If nil is returned, a client will use http rather than https.
  • The QueryCoder package has been moved to QueryCoding.
  • The HTTPClient now needs to be explicitly closed using the close() API. The wait() can be used to block until the client is completely shut down. This was a recommendation from the SwiftNIO team (@weissi).

The are also some additions-

  • The QueryCoder (now QueryCoding) package has been joined with HTTPHeadersCoding and HTTPPathCoding for encoding/decoding headers and paths respectively.
  • The HTTPClient can now be used with an existing EventLoopGroup; it may be more efficient for an application to share ELGs across clients and/or other components. This was also a recommendation from the SwiftNIO team (@weissi).