All Projects → levigross → Grequests

levigross / Grequests

Licence: apache-2.0
A Go "clone" of the great and famous Requests library

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Grequests

RESTEasy
REST API calls made easier
Stars: ✭ 12 (-99.35%)
Mutual labels:  http-client, requests
Node Request Retry
💂 Wrap NodeJS request module to retry http requests in case of errors
Stars: ✭ 330 (-82.09%)
Mutual labels:  http-client, requests
axios-for-observable
A RxJS wrapper for axios, same api as axios absolutely
Stars: ✭ 13 (-99.29%)
Mutual labels:  http-client, requests
Rxios
A RxJS wrapper for axios
Stars: ✭ 119 (-93.54%)
Mutual labels:  http-client, requests
Uplink
A Declarative HTTP Client for Python
Stars: ✭ 824 (-55.29%)
Mutual labels:  http-client, requests
resto
🔗 a CLI app can send pretty HTTP & API requests with TUI
Stars: ✭ 113 (-93.87%)
Mutual labels:  http-client, requests
Requester
Powerful, modern HTTP/REST client built on top of the Requests library
Stars: ✭ 273 (-85.19%)
Mutual labels:  http-client, requests
Php Curl Class
PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs
Stars: ✭ 2,903 (+57.51%)
Mutual labels:  http-client, requests
Requests3
Requests 3.0, for Humans and Machines, alike. 🤖
Stars: ✭ 813 (-55.89%)
Mutual labels:  http-client, requests
Restclient
🦄 Simple HTTP and REST client for Unity based on Promises, also supports Callbacks! 🎮
Stars: ✭ 675 (-63.37%)
Mutual labels:  http-client, requests
fennch
Modern fetch-based axios-like HTTP client for the browser and node.js
Stars: ✭ 12 (-99.35%)
Mutual labels:  http-client, requests
Snug
Write reusable web API interactions
Stars: ✭ 108 (-94.14%)
Mutual labels:  http-client, requests
pawn-requests
pawn-requests provides an API for interacting with HTTP(S) JSON APIs.
Stars: ✭ 56 (-96.96%)
Mutual labels:  http-client, requests
curly.hpp
Simple cURL C++17 wrapper
Stars: ✭ 48 (-97.4%)
Mutual labels:  http-client, requests
Libhv
🔥 比libevent、libuv更易用的国产网络库。A c/c++ network library for developing TCP/UDP/SSL/HTTP/WebSocket client/server.
Stars: ✭ 3,355 (+82.04%)
Mutual labels:  http-client, requests
Guzzle
Guzzle, an extensible PHP HTTP client
Stars: ✭ 21,384 (+1060.28%)
Mutual labels:  http-client, requests
Saber
⚔️ Saber, PHP异步协程HTTP客户端 | PHP Coroutine HTTP client - Swoole Humanization Library
Stars: ✭ 866 (-53.01%)
Mutual labels:  http-client, requests
Python Simple Rest Client
Simple REST client for python 3.6+
Stars: ✭ 143 (-92.24%)
Mutual labels:  http-client, requests
Incapsula Cracker Py3
Python3 compatible way to bypass sites guarded with Incapsula
Stars: ✭ 132 (-92.84%)
Mutual labels:  requests
Gsoc Organisation Scraper
Scrape GSoC organisations using a single script.
Stars: ✭ 121 (-93.43%)
Mutual labels:  requests

GRequests

A Go "clone" of the great and famous Requests library

Build Status GoDoc Coverage Status Join the chat at https://gitter.im/levigross/grequests

License

GRequests is licensed under the Apache License, Version 2.0. See LICENSE for the full license text

Features

  • Responses can be serialized into JSON and XML
  • Easy file uploads
  • Easy file downloads
  • Support for the following HTTP verbs GET, HEAD, POST, PUT, DELETE, PATCH, OPTIONS

Install

go get -u github.com/levigross/grequests

Usage

import "github.com/levigross/grequests"

Basic Examples

Basic GET request:

resp, err := grequests.Get("http://httpbin.org/get", nil)
// You can modify the request by passing an optional RequestOptions struct

if err != nil {
	log.Fatalln("Unable to make request: ", err)
}

fmt.Println(resp.String())
// {
//   "args": {},
//   "headers": {
//     "Accept": "*/*",
//     "Host": "httpbin.org",

If an error occurs all of the other properties and methods of a Response will be nil

Quirks

Request Quirks

When passing parameters to be added to a URL, if the URL has existing parameters that contradict with what has been passed within ParamsParams will be the "source of authority" and overwrite the contradicting URL parameter.

Lets see how it works...

ro := &RequestOptions{
	Params: map[string]string{"Hello": "Goodbye"},
}
Get("http://httpbin.org/get?Hello=World", ro)
// The URL is now http://httpbin.org/get?Hello=Goodbye

Response Quirks

Order matters! This is because grequests.Response is implemented as an io.ReadCloser which proxies the http.Response.Body io.ReadCloser interface. It also includes an internal buffer for use in Response.String() and Response.Bytes().

Here are a list of methods that consume the http.Response.Body io.ReadCloser interface.

  • Response.JSON
  • Response.XML
  • Response.DownloadToFile
  • Response.Close
  • Response.Read

The following methods make use of an internal byte buffer

  • Response.String
  • Response.Bytes

In the code below, once the file is downloaded – the Response struct no longer has access to the request bytes

response := Get("http://some-wonderful-file.txt", nil)

if err := response.DownloadToFile("randomFile"); err != nil {
	log.Println("Unable to download file: ", err)
}

// At this point the .String and .Bytes method will return empty responses

response.Bytes() == nil // true
response.String() == "" // true

But if we were to call response.Bytes() or response.String() first, every operation will succeed until the internal buffer is cleared:

response := Get("http://some-wonderful-file.txt", nil)

// This call to .Bytes caches the request bytes in an internal byte buffer – which can be used again and again until it is cleared
response.Bytes() == `file-bytes`
response.String() == "file-string"

// This will work because it will use the internal byte buffer
if err := resp.DownloadToFile("randomFile"); err != nil {
	log.Println("Unable to download file: ", err)
}

// Now if we clear the internal buffer....
response.ClearInternalBuffer()

// At this point the .String and .Bytes method will return empty responses

response.Bytes() == nil // true
response.String() == "" // true
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].