Quickstart

Quickstart: use the Credicorp public API in Ruby on Rails

Here is the idiomatic way to call the Credicorp public API from Ruby on Rails. Fetch the product catalogue, cache it, and read the base host from configuration — the same shape you extend later for pricing and quotes, always keeping partner secrets server-side.

2 min read

Ruby on RailsIdiomatic integration
cacheCatalogue changes rarely
configBase URL from env

Call the API from Ruby on Rails

class CredicorpClient
  BASE = ENV.fetch('CREDICORP_BASE')

  def products
    Rails.cache.fetch('credicorp_products', expires_in: 1.hour) do
      uri = URI("#{BASE}/products")
      res = Net::HTTP.get_response(uri)
      raise "Credicorp #{res.code}" unless res.code.to_i < 400
      JSON.parse(res.body)['data']
    end
  end
end

Put the call in a service object, read the base URL from `ENV`, and wrap it in `Rails.cache.fetch` so the catalogue is cached for an hour. Keep controllers thin — they should call the service, not the API.

Point at sandbox in development

Set the base URL to https://sandbox.credicorp.co.uk/public/v1 in development and CI, and to https://api.credicorp.co.uk/public/v1 in production — driven by the one environment variable your framework already exposes. See choosing a base URL.

Next steps

From here you can add a quote form, an enquiry submission or an embeddable product picker. Send applicants to apply to start a real journey.

Frequently asked questions

Service object or model?

A plain service object (PORO) is the right home for an outbound API call. Keep it out of your ActiveRecord models so your domain stays free of HTTP concerns.

Should I cache the product list?

Yes. The catalogue changes infrequently, so cache it for the response's max-age. This keeps the API off your hot path and well under the rate limit.

Funding for UK limited companies

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