

# Use a Ruby SDK generated by API Gateway for a REST API


The following procedure shows how to use a Ruby SDK generated by API Gateway.

**Note**  
These instructions assume you already completed the instructions in [Generate SDKs for REST APIs in API Gateway](how-to-generate-sdk.md).

**To install, instantiate, and call a Ruby SDK generated by API Gateway for a REST API**

1. Unzip the downloaded Ruby SDK file. The generated SDK source is shown as follows.  
![\[Unzip the downloaded Ruby SDK file into a Ruby module\]](http://docs.aws.amazon.com/apigateway/latest/developerguide/images/ruby-gem-of-generated-sdk-for-simplecalc.png)

   

1.  Build a Ruby Gem from the generated SDK source, using the following shell commands in a terminal window:

   ```
   # change to /simplecalc-sdk directory
   cd simplecalc-sdk
   
   # build the generated gem
   gem build simplecalc-sdk.gemspec
   ```

   After this, **simplecalc-sdk-1.0.0.gem** becomes available.

1.  Install the gem:

   ```
   gem install simplecalc-sdk-1.0.0.gem
   ```

1.  Create a client application. Instantiate and initialize the Ruby SDK client in the app:

   ```
   require 'simplecalc-sdk'
   client = SimpleCalc::Client.new(
       http_wire_trace: true,
       retry_limit: 5,
       http_read_timeout: 50
   )
   ```

   If the API has authorization of the `AWS_IAM` type is configured, you can include the caller's AWS credentials by supplying `accessKey` and `secretKey` during the initialization:

   ```
   require 'pet-sdk'
   client = Pet::Client.new(
       http_wire_trace: true,
       retry_limit: 5,
       http_read_timeout: 50,
       access_key_id: 'ACCESS_KEY',
       secret_access_key: 'SECRET_KEY'
   )
   ```

1.  Make API calls through the SDK in the app. 
**Tip**  
 If you are not familiar with the SDK method call conventions, you can review the `client.rb` file in the generated SDK `lib` folder. The folder contains documentation of each supported API method call.

   To discover supported operations:

   ```
   # to show supported operations:
   puts client.operation_names
   ```

   This results in the following display, corresponding to the API methods of `GET /?a={.}&b={.}&op={.}`, `GET /{a}/{b}/{op}`, and `POST /`, plus a payload of the `{a:"…", b:"…", op:"…"}` format, respectively:

   ```
   [:get_api_root, :get_ab_op, :post_api_root]
   ```

   To invoke the `GET /?a=1&b=2&op=+` API method, call the following the Ruby SDK method:

   ```
   resp = client.get_api_root({a:"1", b:"2", op:"+"})
   ```

   To invoke the `POST /` API method with a payload of `{a: "1", b: "2", "op": "+"}`, call the following Ruby SDK method:

   ```
   resp = client.post_api_root(input: {a:"1", b:"2", op:"+"})
   ```

   To invoke the `GET /1/2/+` API method, call the following Ruby SDK method:

   ```
   resp = client.get_ab_op({a:"1", b:"2", op:"+"})
   ```

   The successful SDK method calls return the following response:

   ```
   resp : {
       result: {
           input: {
               a: 1,
               b: 2,
               op: "+"
           },
           output: {
               c: 3
           }
       }
   }
   ```