Ruby · Net::HTTP

Use Backfire from Ruby

Rails apps and background workers make outbound calls constantly. One relay endpoint gives them a shared safety check and a written record of every external request.

Notes for this client

  • Net::HTTP, Faraday or HTTParty all work — it is a JSON POST over HTTPS.
  • Read the key from ENV.fetch so a missing secret fails loudly at boot.
  • Set open and read timeouts on the client in addition to timeout_ms.
  • Parse with JSON.parse and branch on envelope["ok"].

Working example

ruby
require 'net/http'
require 'json'

uri = URI('https://backfireapi.base44.app/functions/forward')
request = Net::HTTP::Post.new(uri)
request['Authorization'] = "Bearer #{ENV.fetch('BACKFIRE_KEY')}"
request['Content-Type'] = 'application/json'
request.body = JSON.generate(
  url: 'https://api.github.com/zen',
  method: 'GET',
  timeout_ms: 8000
)

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, read_timeout: 30) do |http|
  http.request(request)
end

envelope = JSON.parse(response.body)
raise envelope['error']['code'] unless envelope['ok']
puts envelope['body']['text']

Questions about this

Other languages

Try it with 5,000 free trips.

No card, no subscription, and the balance never expires.