• Stars
    star
    1,991
  • Rank 23,267 (Top 0.5 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created over 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

GRequests

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

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 Params – Params 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

More Repositories

1

go-mutual-tls

How to make use of mutual TLS authentication in Go
Go
77
star
2

PSAM-5150

Python
18
star
3

Project-Voodo

Python
11
star
4

keylesscrypto

This is an example of using the Shamir secret sharing algorithm to hide the key and encrypt something
Go
8
star
5

mabul

Mabul is a tool used to test DDoS vectors
Go
7
star
6

Sully

Sulley is a fuzzer development and fuzz testing framework consisting of multiple extensible components. Sulley (IMHO) exceeds the capabilities of most previously published fuzzing technologies, commercial and public domain. The goal of the framework is to simplify not only data representation but to simplify data transmission and target monitoring as well. Sulley is affectionately named after the creature from Monsters Inc., because, well, he is fuzzy.
Python
6
star
7

circular

A lock free circular buffer in Go
Go
5
star
8

grequests-crawler

This is a web crawler written using Grequests
Go
5
star
9

Scapy

Scapy
Python
5
star
10

go-tunnel

A STunnel Replacement written in Go
Go
5
star
11

connectors

A series of customized structs that conform to the net.Conn interface
Go
4
star
12

gllrb

Left Leaning Red Black Tree written in Go
Go
4
star
13

gboringssltls

This is a slight fork of the boring https://boringssl.googlesource.com/boringssl/ TLS test runner
Go
3
star
14

constant_time_compare

This is a constant time comparison written in C for Python 2.7.x
C
2
star
15

DjanGoat

This is an example of a vulnerable Django web application
Python
2
star
16

ChaCha20

ChaCha20 as defined in https://tools.ietf.org/html/rfc7539
Go
2
star
17

Python-Style-Guide

My Personal Python Style Guide
2
star
18

nixos-pxe

My Nixos PXE setup
Nix
1
star
19

python-sdk

Facebook Platform Python SDK
Python
1
star
20

py-html-contextual-escaping

This is a fork of https://code.google.com/p/py-html-contextual-escaping/
Python
1
star
21

headless-kali-container

Dockerfile for Headless kali linux
Dockerfile
1
star
22

encrypted-secret-operator

An operator designed to allow for encrypted secrets in Kubernetes
Go
1
star
23

Secure-Python-Guide

This is a guide on how to write Secure Python code
1
star
24

How-To-Use-Git

1
star
25

Crazy-Wallaby

Something like crazy monkey
Python
1
star
26

mach-osx

A collections of tools to make use of Mach in OSX
C
1
star
27

IPv6-Tools

Pentesting tools for IPv6
1
star
28

netSensor

Cloned From http://acm.poly.edu/svn/netSensor/
C++
1
star
29

pyscanner

A tool used to scan Python source code
Python
1
star
30

tcp-multiplexer

An example of using QUIC to multiplex multiple TCP connections over one QUIC stream
Go
1
star
31

CTF

CTF
JavaScript
1
star