SoarHttpClient
Installation
Add this line to your application's Gemfile:
gem 'soar_http_client'
And then execute:
$ bundle
Or install it yourself as:
$ gem install soar_http_client
Usage
All HTTP verbs are supported.
GET
client = SoarHttpClient.new(url: "http://localhost")
response = client.get(
path: '/folder1', params: { 'param1' => 'somedata' }
)
response.status #==> 200
response.body #==> 'body data'
POST
client = SoarHttpClient.new(url: "http://localhost")
response = client.post(
path: '/folder1', body: { 'param1' => 'somedata' }
)
response.status #==> 200
response.body #==> 'body data'
Connection options
persistent_connection
Persistent connections is support by NetHttpPersistent. By default persistent connections are turned off.
client = SoarHttpClient.new(url: "http://localhost", persistent_connection: true)
timeout
The default timeout value is 5 seconds. This sets the open_timeout and read_timeout value.
client = SoarHttpClient.new(url: "http://localhost", timeout: 10)
Retries
Default retry value is 2
client = SoarHttpClient.new(url: "http://localhost", retries: 3)
Auditing
Retries and Max retries reached can be audited by passing in a configured instance of SoarAuditingProvider with the auditing parameter.
client = SoarHttpClient.new(url: "http://localhost", auditing: auditing)
Basic Auth
client = SoarHttpClient.new(url: "http://localhost", basic_auth: { user: 'user', password: 'secret' })
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Running specs in docker
docker-compose build --force-rm --no-cache
docker-compose run -u $UID:$UID --rm soar-http-client /bin/bash -c 'bundle exec rspec'
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/hetznerZA/soar_http_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.