Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jgaskins/http_client
Pooling-enabled HTTP client for Crystal
https://github.com/jgaskins/http_client
Last synced: 2 months ago
JSON representation
Pooling-enabled HTTP client for Crystal
- Host: GitHub
- URL: https://github.com/jgaskins/http_client
- Owner: jgaskins
- License: mit
- Created: 2024-07-21T20:30:33.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-08-01T01:53:45.000Z (5 months ago)
- Last Synced: 2024-08-02T04:39:27.797Z (5 months ago)
- Language: Crystal
- Size: 3.91 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `HTTPClient`
A HTTP client that transparently pools connections. You can use it anywhere you would use an [`HTTP::Client`](https://crystal-lang.org/api/1.13.1/HTTP/Client.html) because it *is* an `HTTP::Client`.
## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
http_client:
github: jgaskins/http_client
```2. Run `shards install`
## Usage
```crystal
require "http_client"http = HTTPClient.new(URI.parse("https://api.example.com"))
http.get "/"
# => #
```### OAuth
Using a pooled HTTP client allows you to use a single `OAuth2::Client` instance for your entire app.
```crystal
require "oauth2"
require "http_client"EXAMPLE_OAUTH2 = OAuth2::Client.new(
host: "api.example.com",
client_id: ENV["OAUTH2_CLIENT_ID"],
client_secret: ENV["OAUTH2_CLIENT_SECRET"],
redirect_uri: ENV["OAUTH2_REDIRECT_URI"],
)
EXAMPLE_OAUTH2.http_client = HTTPClient.new("https://api.example.com")
```## Contributing
1. Fork it ()
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request## Contributors
- [Jamie Gaskins](https://github.com/jgaskins) - creator and maintainer