Skip to main content
Version: 1.4.1

POST

To configure a route with the post method just configure your httpMethod with .post and task with .requestEncoder with protocol VCodable or other type of task.

For your request you can choose different tasks, For example.

Type of Tasks.

.requestBody([
"name": "Victor",
"lastname": "Freitas"
]) // Body

.requestEncoder(model) // Body
.requestURLParameters(urlParameters: ["transactionId": "ID"]) // Query String
.requestParameters(bodyParameters: ["name": "Victor"], urlParameters: ["transactionId": "ID"]) // Body with Query String.

VCodable Model Example.

struct ExampleModel: VCodable {
var name: String
var lastname: String
}

POST Example

enum HomeAPI {
case home(ExampleModel)
}

extension HomeAPI: APIBuilder {

var path: URLPath {
switch self {
case .home:
return .plain("jokes/random")
}
}

var httpMethod: HTTPMethods {
switch self {
case .home:
return .post // Define method POST
}
}

var headers: HTTPHeader {
.bearer("yourToken")
}

var task: HTTPTask {
switch self {
case let .home(model):
return .requestEncoder(model) // This performs a request with a body conforms protocol VCodable.
}
}
}