import Vapor import BinaryCodable private let responseEncoder = BinaryEncoder() private let requestDecoder = BinaryDecoder() var serverStatus: ServerStatus = .starting func routes(_ app: Application) throws { app.post("token") { req async throws -> HTTPResponseStatus in guard let data = req.body.data?.allReadableBytes else { return .badRequest } let tokenUpload: TokenUpload = try requestDecoder.decode(from: data) tokenStorage.add(tokenUpload) return .ok } app.get("status") { req async throws -> Response in let data = try responseEncoder.encode(serverStatus) return Response(status: .ok, body: .init(data: data)) } } private extension ByteBuffer { var allReadableBytes: Data? { getData(at: 0, length: readableBytes) } }