All Projects β†’ serradura β†’ Request_via

serradura / Request_via

Licence: mit
RequestVia: A Functional HTTP Client That Wraps Net::HTTP

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Request via

Pampy.js
Pampy.js: Pattern Matching for JavaScript
Stars: ✭ 544 (+635.14%)
Mutual labels:  functional-programming, functional
Ramtuary
Ramda + Ramda Fantasy + Sanctuary REPL 🌿
Stars: ✭ 72 (-2.7%)
Mutual labels:  functional-programming, functional
Functional Programming Learning Path
A Learning Path for Functional Programming
Stars: ✭ 582 (+686.49%)
Mutual labels:  functional-programming, functional
Yalinqo
Yet Another LINQ to Objects for PHP [Simplified BSD]
Stars: ✭ 400 (+440.54%)
Mutual labels:  functional-programming, functional
Rexrex
πŸ¦– Composable JavaScript regular expressions
Stars: ✭ 34 (-54.05%)
Mutual labels:  functional-programming, functional
Hof
Higher-order functions for c++
Stars: ✭ 467 (+531.08%)
Mutual labels:  functional-programming, functional
Gun
HTTP/1.1, HTTP/2 and Websocket client for Erlang/OTP.
Stars: ✭ 710 (+859.46%)
Mutual labels:  http-client, functional
Eslint Plugin Functional
ESLint rules to disable mutation and promote fp in JavaScript and TypeScript.
Stars: ✭ 282 (+281.08%)
Mutual labels:  functional-programming, functional
Swiftlyext
SwiftlyExt is a collection of useful extensions for Swift 3 standard classes and types πŸš€
Stars: ✭ 31 (-58.11%)
Mutual labels:  functional-programming, functional
Immutable Tuple
Immutable finite list objects with constant-time equality testing (===) and no memory leaks.
Stars: ✭ 29 (-60.81%)
Mutual labels:  functional-programming, functional
Carp
Carp is a programming language designed to work well for interactive and performance sensitive use cases like games, sound synthesis and visualizations.
Stars: ✭ 4,389 (+5831.08%)
Mutual labels:  functional-programming, functional
Kari.hpp
Experimental library for currying in C++17
Stars: ✭ 58 (-21.62%)
Mutual labels:  functional-programming, functional
Kotlin Result
A multiplatform Result monad for modelling success or failure operations.
Stars: ✭ 369 (+398.65%)
Mutual labels:  functional-programming, functional
Moses
Utility library for functional programming in Lua
Stars: ✭ 541 (+631.08%)
Mutual labels:  functional-programming, functional
Coconut
Simple, elegant, Pythonic functional programming.
Stars: ✭ 3,422 (+4524.32%)
Mutual labels:  functional-programming, functional
Fkit
A functional programming toolkit for JavaScript.
Stars: ✭ 588 (+694.59%)
Mutual labels:  functional-programming, functional
Request Compose
Composable HTTP Client
Stars: ✭ 80 (+8.11%)
Mutual labels:  http-client, functional-programming
httoop
HTTOOP - a fully object oriented HTTP protocol library written in python
Stars: ✭ 15 (-79.73%)
Mutual labels:  uri, http-client
Kaur
A bunch of helper functions to ease the development of your applications.
Stars: ✭ 17 (-77.03%)
Mutual labels:  functional-programming, functional
Inferno Most Fp Demo
A demo for the ReactJS Tampa Bay meetup showing how to build a React+Redux-like architecture from scratch using Inferno, Most.js, reactive programmning, and various functional programming tools & techniques
Stars: ✭ 45 (-39.19%)
Mutual labels:  functional-programming, functional

RequestVia

A fast and functional (API and paradigm) HTTP client, using only Ruby's standard library as dependency. e.g: Net::HTTP and URI.

gif

List of all commands shown in the GIF:

require 'request_via'

# Thanks to @ElliottLandsborough Dog CEO API (https://github.com/ElliottLandsborough/dog-ceo-api)

# --- Single request

response = RequestVia::Get.('https://dog.ceo/api/breed/boxer/images/random')
response.body

# --- Make requests over a map iteration

dogs = [ 'akita', 'chihuahua', 'beagle' ]
dog_images = dogs.map { |breed_name| "https://dog.ceo/api/breed/#{breed_name}/images/random" }
dog_images.map(&RequestVia::Get).map(&:body)

# If do you want to pass common arguments for each request use the GetR function (R = reversed arguments)
# Available options: port, params, headers, open_timeout read_timeout, response_and_request, net_http
dog_images.map(&RequestVia::GetR.(open_timeout: 10)).map(&:body)

# --- Make requests over an ASYNC map iteration

require 'parallel' # https://rubygems.org/gems/parallel

Parallel.map(dog_images, &RequestVia::Get).map(&:body)

# Apply common options for each request
Parallel.map(dog_images, &RequestVia::GetR.(open_timeout: 10)).map(&:body)

Installation

Add this line to your application's Gemfile:

gem 'request_via'

And then execute:

$ bundle

Or install it yourself as:

$ gem install request_via

Usage

Making a HTTP GET request

# Use http:// as the protocol when there is no one defined.
RequestVia::Get.call('example.com')

RequestVia::Get.call('http://example.com')

# We recommend to use the `.()` syntax to invoke/make the HTTP requests.
# Read more about this: https://ruby-doc.org/core-2.2.2/Proc.html#method-i-call
RequestVia::Get.('example.com')

# Request with params
RequestVia::Get.('example.com', params: { foo: 'bar' })

# Request with headers
RequestVia::Get.('example.com/foo', headers: { 'X-Requested-With': 'RequestVia gem' })

# Return the response and request objects
response, request = RequestVia::Get.('example.com/foo', response_and_request: true)

# Request with the reversed arguments order
%w[
  example.com/foo example.com/bar
].map &RequestVia::GetR.(headers: { 'X-Requested-With': 'RequestVia gem' })

# Other options
RequestVia::Get.('example.io', port: 2000,
                               open_timeout: 10,  # Default: 60
                               read_timeout: 120, # Default: 60
                               net_http: -> (host, port) {
                                   net_http = Net::HTTP.new(host, port)
                                   # Make your customizations
                                   net_http
                               })

Supported HTTP methods. (NOTE: you can use all arguments of previous examples)

RequestVia::Head.()    # RequestVia::HeadR.()

RequestVia::Post.()    # RequestVia::PostR.()

RequestVia::Put.()     # RequestVia::PutR.()

RequestVia::Delete.()  # RequestVia::DeleteR.()

RequestVia::Options.() # RequestVia::OptionsR.()

RequestVia::Trace.()   # RequestVia::TraceR.()

RequestVia::Patch.()   # RequestVia::PatchR.()

Making a HTTPS request.

RequestVia::Get.('https://example.com')

Create a HTTP(S) client for REST resources.

client = RequestVia::Client.('https://example.com')

client.get # same of client.get('/')

# Supported arguments: params:, headers:
client.get(params: { a: 1 }, headers: { 'Header-Name' => 'Header-Value' })

client.get('foo', params: { a: 1 })

client.get('/bar', headers: { 'User-Agent' => 'REST Example' })

# Supported HTTP methods:
# client.get
# client.head
# client.post
# client.put
# client.delete
# client.options
# client.trace
# client.patch

# Supported options
RequestVia::Client.('example.com/foo/bar', port: 3000,
                                           open_timeout: 10,
                                           read_timeout: 100)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test 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.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/request_via. 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.

Code of Conduct

Everyone interacting in the RequestVia project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].