Quickstart

Quickstart: call the Credit Corp public API from Swift

Here is the idiomatic Swift way to make your first Credit Corp public API call. List the live products from GET /public/v1/products, set a timeout, and turn the documented error envelope into an error you can handle — the pattern every other public-ring call reuses.

2 min read

SwiftFirst call
timeoutBound every request
data[]Unwrap the envelope

List products

var req = URLRequest(url: URL(string:
  "https://api.credicorp.co.uk/public/v1/products")!)
req.setValue("application/json", forHTTPHeaderField: "Accept")
req.timeoutInterval = 10
let (data, resp) = try await URLSession.shared.data(for: req)
guard (resp as? HTTPURLResponse)?.statusCode ?? 500 < 400 else {
  throw ApiError.badStatus
}
let list = try JSONDecoder().decode(ProductList.self, from: data)

Use URLSession with async/await and a Decodable model. On iOS, run the request off the main actor and open the enquiry handoff in an SFSafariViewController.

Use the sandbox in development

Point the base host at https://sandbox.credicorp.co.uk/public/v1 in development and CI, and at https://api.credicorp.co.uk/public/v1 in production, driven by one environment variable. See choosing a base URL.

Next steps

From here, request a quote, submit an enquiry, and send applicants to apply. Handle errors with the shared error envelope.

Frequently asked questions

Should I add a dependency like Alamofire?

Not for these calls. URLSession with async/await is clean and dependency-free. Alamofire is optional convenience if you already use it.

How do I handle errors in Swift?

Check the status code and read the error object from the body — error.code is the stable machine string to branch on. The pattern is identical across every endpoint.

Funding for UK limited companies

Credit Corp lends to your company, not to you personally — short-term working capital with no personal guarantee. See what your business could access.