Coder Social home page Coder Social logo

requests's Introduction

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

requests's People

Contributors

cyx avatar dcadenas avatar foca avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.