https://github.com/davydovanton/dry-http-client
This repository is no longer maintain: Fundctional HTTP client based on dry stack.
https://github.com/davydovanton/dry-http-client
Last synced: 3 months ago
JSON representation
This repository is no longer maintain: Fundctional HTTP client based on dry stack.
- Host: GitHub
- URL: https://github.com/davydovanton/dry-http-client
- Owner: davydovanton
- License: mit
- Created: 2018-03-20T23:32:32.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-10-06T00:04:47.000Z (over 2 years ago)
- Last Synced: 2025-02-12T22:20:36.907Z (5 months ago)
- Language: Ruby
- Homepage:
- Size: 60.5 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# NOT MAINTAINED
**This repository is no longer maintain**
# Dry::Http::Client
**Proof of Concept**, see full todo list in [TODO.md](https://github.com/davydovanton/dry-http-client/blob/master/TODO.md).
Fundctional HTTP client based on dry stack. Inspired by [serradura/request_via](https://github.com/serradura/request_via)
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'dry-http-client'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install dry-http-client
## Usage
```ruby
client = Dry::Http::Client.new(host: 'https://example.com')client.get # GET https://example.com and return dry-result monad
client.get(params: { a: 1 }, headers: { 'Header-Name' => 'Header-Value' })
# => Success(request_object)
# => Success(request_object)# or dry-struct
options = Dry::Http::Client::Options.new(params: { a: 1 }, headers: { 'Header-Name' => 'Header-Value' })
client.get(options)client.get('foo', params: { a: 1 })
client.get('/bar', headers: { 'User-Agent' => 'REST Example' })# also, you can put block in to request:
client.get('foo', params: { a: 1 }) do |request|
request['Header'] = 'Value'
end# Supported HTTP methods:
# client.get
# client.head
# client.post
# client.put
# client.delete
# client.options
# client.trace
# client.patchDry::Http::Client.new(host: 'example.com', port: 3000, open_timeout: 10, read_timeout: 100)
# or with default params
Dry::Http::Client.new(host: 'example.com', params: { key: '...' }, headers: { 'Header-Name' => 'Header-Value' })
```### Response Struct
```ruby
module Types
include Dry::Types.module
endclass UserResponseStruct < Dry::Struct
attribute :name, Types::String
attribute :age, Types::Coercible::Int
endclient.get('users/1', success_struct: UserResponseStruct) # => Success([200, UserResponseStruct.new(name: 'Anton', age: '21')])
```## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/davydovanton/dry-http-client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Code of Conduct
Everyone interacting in the Dry::Http::Client project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/dry-http-client/blob/master/CODE_OF_CONDUCT.md).