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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

requests's Issues

Add a `Request` class?

Following the lines of #1 : would it make sense to get a Request class analog to the Response class?

I'm debugging a problem in which it'd be helpful to have access to both the Requests::Error#response and Requests::Error#request.

I can send a PR with this if you like the idea.

Add redirect support

In python, requests will redirect by default.
but in this library, I can't handle 3xx code.

Give the option to configure timeout

I'm really comfortable with the abstraction provided by this Request gem.

The problem right now is that I want to implement a short circuit an retry after a certain time interval, but I'm not able to pass read_timeout to the Net::HTTP.start method

What do you think about this?

[Question] Would it make sense to also wrap error responses in a Request::Response?

The main objective would be to have a consistent interface for managing success responses and Error responses.

I find Requests::Response interface cleaner than Net::HTTP error responses (EG, response.to_hash to get the response headers is not very communicative nor intuitive, I almost always need to go back to Net:HTTP docs, which are not very communicative either :P)

I think having this consistency can make client code less surprising and might allow a more fluent dev experience.

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.