Sign inGet Started

Ruby SDK

Send email with Grape

Use Parcel Wing from Grape APIs with declared params and helper-backed SDK clients.

Install the SDK

The official Ruby SDK is published as parcelwing.

Terminal

gem install parcelwing

Send from an API resource

Declare request params, keep the API key server-side, and translate SDK errors into JSON API responses.

api.rb

require "grape"
require "parcelwing"
 
class API < Grape::API
format :json
 
helpers do
def parcelwing
@parcelwing ||= ParcelWing::Client.new(api_key: ENV.fetch("PARCELWING_API_KEY"))
end
end
 
resource :emails do
params do
requires :email, type: String
optional :first_name, type: String
end
post :welcome do
emails = parcelwing.emails.send(
from: ENV.fetch("PARCELWING_FROM_EMAIL"),
to: params[:email],
template_alias: "welcome",
template_params: { first_name: params[:first_name] || "friend" }
)
 
{ id: emails.first.fetch("id") }
rescue ParcelWing::Error => error
error!({ error: error.code, request_id: error.request_id }, error.status || 500)
end
end
end

Production notes

  • Keep PARCELWING_API_KEY in server-side environment variables.
  • Use saved templates for onboarding, invites, receipts, and account notifications.
  • Log request_id from ParcelWing::Error for support and debugging.