Skip to content

Instantly share code, notes, and snippets.

Created June 21, 2017 18:48
What would you like to do?
import Foundation
import HTTP
import Vapor
public protocol SideEffect {
func perform() throws
public protocol Command: ResponseRepresentable {
init(request: Request, droplet: Droplet) throws
var status: Status { get }
func validate() throws
var sideEffects: [SideEffect] { get }
func execute() throws -> JSON
extension Command {
public var sideEffects: [SideEffect] {
return []
public func validate() throws {
public func makeResponse() throws -> Response {
let response = Response(status: self.status)
try validate()
response.json = try execute()
try sideEffects.forEach({ try $0.perform() })
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment