It helps you to use microCMS from iOS(Swift) applications.
Check the official documentation for more information
Use swift package manager.
import MicrocmsSDK
let client = MicrocmsClient(
serviceDomain: "YOUR_DOMAIN", // YOUR_DOMAIN is the XXXX part of XXXX.microcms.io
apiKey: "YOUR_API_KEY"
)
client.get(
endpoint: "API_ENDPOINT") { result in
print(result)
}
You can get decoded response like this:
struct Response: Decodable {
let contents: [MyContent]
let totalCount: Int
let offset: Int
let limit: Int
}
client.get(
endpoint: "API_ENDPOINT") { (result: Result<Response, Error>) in
print(result)
}
let params: [MicrocmsParameter] = [
.limit(2),
.filters("createdAt[greater_than]2021")
]
client.get(
endpoint: "API_ENDPOINT",
params: params) { result in
print(result)
}
let params: [MicrocmsParameter] = [
.fields(["id"]),
]
client.get(
endpoint: "API_ENDPOINT",
contentId: "CONTENT_ID",
params: params) { result in
print(result)
}
client.get(
endpoint: "API_ENDPOINT") { result in
print(result)
}
client.create(
endpoint: "API_ENDPOINT",
params: ["text": "Hello iOS SDK!"]) { result in
print(result)
}
client.create(
endpoint: "API_ENDPOINT",
contentId: "CONTENT_ID",
params: ["text": "Hello iOS SDK!"]) { result in
print(result)
}
client.create(
endpoint: "API_ENDPOINT",
params: ["text": "Hello iOS SDK!"],
isDraft: true) { result in
print(result)
}
client.update(
endpoint: "API_ENDPOINT",
contentId: "CONTENT_ID",
params: ["text": "Hello iOS SDK update method!"]) { result in
print(result)
}
client.update(
endpoint: "API_ENDPOINT",
params: ["text": "Hello iOS SDK update method!"]) { result in
print(result)
}
client.delete(
endpoint: "API_ENDPOINT",
contentId: "CONTENT_ID") { result in
print(result)
}