Project

requests

0.04
No release in over 3 years
Low commit activity in last 3 years
Because Requests for Python is awesome
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
 Project Readme

requests

Requests: HTTP for Humans

Description

Inspired by the Requests library for Python, this gem provides an easy way to issue HTTP requests.

Usage

Here's an example of a GET request:

require "requests"

response = Requests.request("GET", "http://example.com")

# Now you have these methods available
response.status  #=> Number with the status code
response.headers #=> Hash with the response headers
response.body    #=> String with the response body

If instead of calling Requests.request you prefer to specify the HTTP method directly, you can use requests/sugar instead:

require "requests/sugar"

response = Requests.get("http://example.com")

# And again you get a response
response.status  #=> Number with the status code
response.headers #=> Hash with the response headers
response.body    #=> String with the response body

You can also pass parameters with a query string:

# GET http://example.com?foo=bar
Requests.get("http://example.com", params: { foo: "bar" })

If you want to send data with a POST request, you can add a data option with the value.

Requests.post("http://example.com", data: "hello world")

For Basic Authentication, you can provide the option auth, which should contain an array with the username and password:

Requests.get("http://example.com", auth: ["username", "password"])

Installation

As usual, you can install it using rubygems.

$ gem install requests