7/24/2023 0 Comments Mobilinc radbeacon![]() It’s quick to learn, quick to pick up, and quick to execute – so with that, I decided to expand my development horizon beyond just. ![]() net and java to other languages – with the first being Ruby. So, without further ado – here’s a quick hit on how to consume APIs using Ruby…īefore we get too far I want to mention that like almost anything there are many ways to consume an API within Ruby – I explored a few of them – net/http, HTTParty, and RestClient. Now there is no right or wrong package to chose, but in my experience, RestClient seemed to be the easiest to work with (that said I haven’t had the chance to check out all of the Ruby packages related to REST). RestClient is a Ruby gem – a gem is basically a library that contains specific pieces of functionality – think of it like an SDK almost, or in. To install RestClient it’s as simple as running gem install rest-client. So let’s break this down a little bit – Lines 7 through 13 encompass our actual API request. As shown, we can see that Line 8 defines the method of the API request, in our case GET – meaning we are going to GET some information. Line 9 defines the URI and resource we want to retrieve the data from, in our case, the vmware/vm resource from the Rubrik cluster – passing our vmname variable within the URI narrows down the results to only those which match. Lines 10 and 11 simply pass our username and password variables – RestClient will automatically convert these to base64 for us and include them in the headers of the call with basic authentication – something which we would normally have to do manually (another reason I chose RestClient).
0 Comments
Leave a Reply. |