/
CodableProtocols.swift
34 lines (31 loc) · 1.21 KB
/
CodableProtocols.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//===----------------------------------------------------------------------===//
//
// This source file is part of the Hummingbird server framework project
//
// Copyright (c) 2021-2021 the Hummingbird authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import HTTPTypes
/// protocol for encoders generating a Response
public protocol ResponseEncoder: Sendable {
/// Encode value returned by handler to request
///
/// - Parameters:
/// - value: value to encode
/// - request: request that generated this value
func encode(_ value: some Encodable, from request: Request, context: some BaseRequestContext) throws -> Response
}
/// protocol for decoder deserializing from a Request body
public protocol RequestDecoder: Sendable {
/// Decode type from request
/// - Parameters:
/// - type: type to decode to
/// - request: request
func decode<T: Decodable>(_ type: T.Type, from request: Request, context: some BaseRequestContext) async throws -> T
}