Clone
2
Usage
Mahtan edited this page 2024-03-21 14:17:15 +00:00

Making requests

let hermes = Hermes()

// GET
let queryParams = ["foo": "bar"]
let resource = Resource(url: "https://httpbin.org/get", method: .get(queryParams), modelType: T.self)

// POST
let postDatas = ["foo": "bar"]
let resource = try Resource(url: "https://httpbin.org/post", method: .post(JSONEncoder().encode(postDatas)), modelType: T.self)

// PUT
let postDatas = ["foo": "bar"]
let resource = try Resource(url: "https://httpbin.org/put", method: .put(JSONEncoder().encode(postDatas)), modelType: T.self)

// PATCH
let postDatas = ["foo": "bar"]
let resource = try Resource(url: "https://httpbin.org/patch", method: .patch(JSONEncoder().encode(postDatas)), modelType: T.self)

// DELETE
let resource = Resource(url: "https://httpbin.org/delete", method: .delete, modelType: T.self)        

// Handle response
let response = try await hermes.load(resource)