AnyAsyncResponse

    A type erased response useful for routes that can return more than one type.

    AnyResponse+Concurrency.swift:35
    struct AnyAsyncResponse
    router.get("foo") { req -> AnyAsyncResponse in
        if /* something */ {
            return AnyAsyncResponse(42)
        } else {
            return AnyAsyncResponse("string")
        }
    }

    This can also be done using a AsyncResponseEncodable enum.

    enum IntOrString: AsyncResponseEncodable {
        case int(Int)
        case string(String)
    
        func encode(for req: Request) throws -> EventLoopFuture<Response> {
            switch self {
            case .int(let i): return try i.encode(for: req)
            case .string(let s): return try s.encode(for: req)
            }
        }
    }
    
    router.get("foo") { req -> IntOrString in
        if /* something */ {
            return .int(42)
        } else {
            return .string("string")
        }
    }

    Citizens in Vapor

    Conformances

    Type members

    Instance members

    Instance features