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 < Rodaplugin :jsonplugin :json_parserparcelwing = ParcelWing::Client.new(api_key: ENV.fetch("PARCELWING_API_KEY"))route do |r|r.post "send-welcome" doemails = 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 => errorresponse.status = error.status || 500{ error: error.code, request_id: error.request_id }endendend
Production notes
- Keep
PARCELWING_API_KEYin server-side environment variables. - Use saved templates for onboarding, invites, receipts, and account notifications.
- Log
request_idfromParcelWing::Errorfor support and debugging.