Modern Apps git

xtool.git

Public
git clone https://git.maproj.org/xtool.git
main ▾

xtool.git / Sources / XKit / GrandSlam / Requests / GrandSlamRequest.swift

GrandSlamRequest.swift49 lines · 1.2 KiBRaw
1//
2// GrandSlamRequest.swift
3// XKit
4//
5// Created by Kabir Oberai on 19/11/19.
6// Copyright © 2019 Kabir Oberai. All rights reserved.
7//
8
9import Foundation
10import HTTPTypes
11
12enum GrandSlamRequestContent {
13 enum ContentType {
14 case xml
15 case json
16 }
17
18 case get
19 case data([String: Any], method: HTTPRequest.Method, type: ContentType = .xml)
20
21 static func post(_ body: [String: Any], type: ContentType = .xml) -> Self {
22 .data(body, method: .post, type: type)
23 }
24
25 static func put(_ body: [String: Any], type: ContentType = .xml) -> Self {
26 .data(body, method: .put, type: type)
27 }
28
29 var httpMethod: HTTPRequest.Method {
30 switch self {
31 case .get: return .get
32 case .data(_, let method, _): return method
33 }
34 }
35}
36
37protocol GrandSlamDataDecoder {
38 associatedtype Value
39 static func decode(data: Data) throws -> Value
40}
41
42protocol GrandSlamRequest: Sendable {
43 associatedtype Decoder: GrandSlamDataDecoder
44
45 static var endpoint: GrandSlamEndpoint { get }
46
47 func configure(request: inout HTTPRequest, anisetteData: AnisetteData)
48 func content(anisetteData: AnisetteData) -> GrandSlamRequestContent
49}