News

Smoke: Amazon’s new lightweight server-side service framework

2 min read

Today, Amazon released Smoke Framework, a lightweight server-side service framework written in the Swift programming language.

The Smoke Framework uses SwiftNIO for its networking layer by default. This 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 also has a built-in support for a JSON-encoded request and response payloads.

Working of Swift-based Smoke Framework

The Smoke Framework provides the ability to specify handlers for operations the 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 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.

Parts of the Smoke framework

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.

The Operation Function

By default, the Smoke framework provides four function signatures that this function can conform to

  • ((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, (SmokeResult<OutputType>) -> ()) 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.

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.

To know more about this in detail, visit Smoke framework’s official GitHub page.

Read Next

ABI stability may finally come in Swift 5.0

Swift 4.2 releases with language, library and package manager updates!

What’s new in Vapor 3, the popular Swift based web framework

Savia Lobo

A Data science fanatic. Loves to be updated with the tech happenings around the globe. Loves singing and composing songs. Believes in putting the art in smart.

Share
Published by
Savia Lobo

Recent Posts

Top life hacks for prepping for your IT certification exam

I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…

3 years ago

Learn Transformers for Natural Language Processing with Denis Rothman

Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…

3 years ago

Learning Essential Linux Commands for Navigating the Shell Effectively

Once we learn how to deploy an Ubuntu server, how to manage users, and how…

3 years ago

Clean Coding in Python with Mariano Anaya

Key-takeaways:   Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…

3 years ago

Exploring Forms in Angular – types, benefits and differences   

While developing a web application, or setting dynamic pages and meta tags we need to deal with…

3 years ago

Gain Practical Expertise with the Latest Edition of Software Architecture with C# 9 and .NET 5

Software architecture is one of the most discussed topics in the software industry today, and…

3 years ago