Skip to content

Latest commit

 

History

History
66 lines (45 loc) · 1.46 KB

README.markdown

File metadata and controls

66 lines (45 loc) · 1.46 KB

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