Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jacobsapps/3b2804b382d6f0682c79af3616be5cfb to your computer and use it in GitHub Desktop.

Select an option

Save jacobsapps/3b2804b382d6f0682c79af3616be5cfb to your computer and use it in GitHub Desktop.
private func makeIdempotencyKey(enabled: Bool) -> String? {
guard enabled else { return nil }
let key = UUID().uuidString
return key
}
private func makePostRequest(text: String, idempotencyKey: String?) throws -> URLRequest {
var request = makeRequest(path: "level2/tweets", method: "POST")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
if let idempotencyKey {
request.setValue(idempotencyKey, forHTTPHeaderField: "Idempotency-Key")
}
request.httpBody = try encoder.encode(Level2PostBody(text: text))
return request
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment