Amazon Smoke框架是使用Swift语言编写的全新开源轻量级服务器端框架,用于构建类REST或类RPC的服务。它的架构设计强调易于使用,以及请求处理程序偏向纯函数编程的风格。
\\通过Amazon Smoke创建服务需要三个步骤:
\\- \\t
定义处理传入的请求的操作。每个这样的操作是通过一个函数定义的,传入OperationInput和通用的ApplicationContext,并同步或异步地返回OperationOutput,如下面的代码所示:
\\\t\
\\t\// Synchronous handler\func handleTheOperation(input: OperationInput, context: MyApplicationContext) throws -\u0026gt; OperationOutput {\ return OperationOutput()\}\\// Asynchronous handler\func handleOperationAsync(input: OperationInput, context: MyApplicationContext,\ responseHandler: (SmokeResult\u0026lt;OutputAttributes\u0026gt;) -\u0026gt; ()) throws {\\ let result = OperationOutput()\ rensponseHandler(.response(attributes))\}\
输入和输出类型必须符合ValidatableCodable协议,该协议可以通过validate函数验证输入和输出字段。
\\- \\t
说明如何选择操作处理程序来处理传入的请求。Smoke提供了一个StandardSmokeHTTP1HandlerSelector,它可以作为类REST服务开箱即用,根据其HTTP动词和URI选择已给定的请求处理程序:
\\\t\
import SmokeOperations\\public typealias HandlerSelectorType =\StandardSmokeHTTP1HandlerSelector\u0026lt;MyApplicationContext, JSONPayloadHTTP1OperationDelegate\u0026gt;\\public func createHandlerSelector() -\u0026gt; HandlerSelectorType {\ var newHandler = HandlerSelectorType()\\ newHandler.addHandlerForUri(\"/theOperationPath\