Sign inGet Started

Ruby SDK

Send email with Roda

Use Parcel Wing from compact Roda APIs with JSON request parsing and structured errors.

Install the SDK

The official Ruby SDK is published as parcelwing.

Terminal

gem install parcelwing

Send from a route

Create the client outside the route block and reuse it for incoming JSON requests.

app.rb

require "json"
require "parcelwing"
require "roda"
 
class App < Roda
plugin :json
plugin :json_parser
 
parcelwing = ParcelWing::Client.new(api_key: ENV.fetch("PARCELWING_API_KEY"))
 
route do |r|
r.post "send-welcome" do
emails = parcelwing.emails.send(
from: ENV.fetch("PARCELWING_FROM_EMAIL"),
to: r.params.fetch("email"),
template_alias: "welcome",
template_params: { first_name: r.params["first_name"] || "friend" }
)
 
{ id: emails.first.fetch("id") }
rescue ParcelWing::Error => error
response.status = error.status || 500
{ error: error.code, request_id: error.request_id }
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.