Jumpstart docs logo Back to the app

API Clients

API Clients

Jumpstart Pro includes a built-in API client generator. You can use it to create your own API clients for integrations with any API you would like.

As developers, it's easy to reach for Rubygems, but each dependency we add makes it harder to maintain your application. We've found that we need to fork most API Rubygems to fix bugs or implement API features that aren't supported yet in the library.

Now, our default is to build an API client ourselves. It's easy to maintain, doesn't break from external changes, and only implements the features we need. We've made this available to Jumpstart Pro users to more easily take advantage of building their own API clients.

To learn more about API Clients in Jumpstart Pro, check out the Net Http API Client from Scratch video on GoRails.

Creating API Clients

Run the API client Rails generator to create an API client.

rails g api_client OpenAi

This generates app/clients/open_ai_client.rb and a matching test file.

To implement API endpoints, you will define methods that make an HTTP request to the API endpoints. Here's an example using the Sendfox API:

class SendfoxClient < ApplicationClient
  BASE_URI = "https://api.sendfox.com/"

  def me
    get "/me"

  def lists
    get "/lists"

  def list(id)
    get "/lists/#{id}"

  def create_list(name:)
    post "/lists", body: {name: name}

  def remove_contact(list_id:, contact_id:)
    delete "/lists/#{list_id}/contacts/#{contact_id}"

  def contacts(email: nil)
    if email
      get "/contacts?email=#{CGI.escape(email)}"
      get "/contacts"

  def contact(id)
    get "/contacts/#{id}"

  def create_contact(**params)
    post "/contacts", body: params

  def unsubscribe(email:)
    patch "/unsubscribe", body: {email: email}

  def campaigns
    get "/campaigns"

  def campaign(id)
    get "/#{id}"


ApplicationClient is the base class that API clients inherit from. It provides methods for get, post, patch, put, and delete. It also handles authorization using the Authorization header and parsing response bodies as JSON.

You can override these methods in your API client to match your API. For example, if you need to parse XML instead of JSON, override the parse_response method and use Nokogiri instead.

More features

Optionally pass the --url option to set the base URL

Optionally pass methods with index, show, create, update, destroy types

rails g api_client OpenAi completions:create --url https://api.openai.com