How to get and post from ruby

Asked 2 years ago, Updated 2 years ago, 32 views

How can ruby throw parameters to any URL with post, get, etc.?

ruby

2022-09-29 22:43

3 Answers

HTTP Client libraries make it easy.
There are several implementations of the HTTP Client library, and the following are well known:

rest-client
faraday
httpclient

In github, the number of stars is higher from the top.
You can find some instructions on how to use it by browsing the github page or searching on Google.


2022-09-29 22:43

For most applications, net/http or open-uri is acceptable for GET only.Both libraries are attached to the ruby body, so you can definitely use them in the environment where ruby is included.

If you're asking the assumption that a standard library is inconvenient, you'll get a better answer if you add what you want to do for what purpose and what's inconvenient about a standard library.


2022-09-29 22:44

I recently started Ruby, but
in net/http Net::HTTP
Net::HTTP::Post
Net::HTTP::Get
I think I can do it around here.

If you have similar implementation experience in other languages, it will be relatively easy to implement by referring to the links shared by others and the TIPS that you search for.

Below is the code I wrote, and I switch POST/GET within the same method and pass the parameters to the external URL (in this case, PayPal API) to get the results.

https://github.com/benzookapi/PayPalRubyDemo/blob/master/app/models/pp_rest.rb#L38

(Although error handling is not done properly)


2022-09-29 22:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.