This guide provides instructions for using Ruby SDKs generated by Postman SDK Generator. It covers how to install the SDK into your project, run example code, and best practices for using the SDK effectively in your applications.
The Postman SDK Generator creates Ruby SDKs with models, service classes for API endpoints, authentication handling, error handling, and comprehensive documentation to help you integrate with your API quickly and efficiently. Models include attribute validation, serialization support, and clear error messages to enhance development experience.
Generated Ruby SDKs include the following key components:
lib/[sdk_name].rb for SDK initialization and configuration.lib/[sdk_name]/services/ with individual service classes.lib/[sdk_name]/models/ with validation and serialization.lib/[sdk_name]/http/ handling HTTP transport, configuration, and authentication.The directory structure includes documentation files, example implementations, and gemspec configuration for Ruby ecosystem integration.
The following is an example of the typical structure of a generated Ruby SDK:
Generated Ruby models follow Ruby conventions and best practices, providing a natural Ruby development experience.
Models serialize to API-compatible hashes using to_h, which applies field aliases and excludes unset attributes:
The SDK uses Ruby naming conventions (snake_case) for model attributes and service methods, and converts to API field names (camelCase) during serialization. This allows you to work with Ruby idioms while ensuring correct API communication.
Each generated SDK includes an example/ directory with a working project demonstrating SDK usage.
The example includes the following features:
example/example.rb
You can install the generated SDK into your Ruby project using Bundler, RubyGems, or by adding it to your load path. Below are instructions for each method.
To install the SDK using Bundler with a local path, do the following:
Add the SDK to your Gemfile:
Install dependencies:
Use the SDK in your code:
To install the SDK directly from a Git repository, add the following to your Gemfile:
To share your generated Ruby SDK with the community, you can publish it to RubyGems. This allows other developers to easily install it using gem install. Follow the steps below to publish your SDK to RubyGems.
To publish your SDK to RubyGems, do the following:
If you haven’t done so, create a RubyGems account:
Prepare your gem for publishing:
This creates your-sdk-1.0.0.gem in the current directory.
Validate the gem:
Publish to RubyGems:
Verify publication:
Update the version in lib/your_sdk/version.rb:
Update CHANGELOG.md with changes.
Build and publish:
Use the following best practices when publishing your Ruby SDK to RubyGems:
MAJOR.MINOR.PATCH).CHANGELOG.md documenting changes.