Forum Discussion

hundredbillion's avatar
hundredbillion
New Member
4 years ago

Ruby on Rails Swagger Client Confusion.

I am a junior developer trying to get better at API's and consuming API's. There are some gaps in my understanding, but if anyone can help, I would appreciate it.

I have a Golang web app that I made into an API with Swagger Codegen
I have a Ruby on Rails web app that has the gem 'swagger_client', '~> 1.0.0' in the Gemfile.
My plan was to use my Rails controller and pass form data in my 
def create, def update, def destroy methods
to my Golang database, but I am not understanding how I can hit my Golang endpoints.


When I generated the Ruby Client, the README has the following information, but it is confusing to me.
1. 


# Load the gem
require 'swagger_client'


But where do I "require 'swagger_client'"? 

 

2.

api_instance = SwaggerClient::DefaultApi.new

post = SwaggerClient::PressReleasePostNew.new # PressReleasePostNew | Json object of data for the new Press Release Post.


begin
  result = api_instance.post_create(post)
  p result
rescue SwaggerClient::ApiError => e
  puts "Exception when calling DefaultApi->post_create: #{e}"
end


But where do I add this block of code?

Am I not understanding what the Ruby Client SDK is supposed to be used for?

No RepliesBe the first to reply