All Projects → xuanbo → requests

xuanbo / requests

Licence: other
http requests lib for golang

Programming Languages

go
31211 projects - #10 most used programming language

Labels

Projects that are alternatives of or similar to requests

dnevnikru
dnevnik.ru parser
Stars: ✭ 20 (-70.15%)
Mutual labels:  requests
option chain analysis
NSE Nifty Option chain analysis on the web page.
Stars: ✭ 63 (-5.97%)
Mutual labels:  requests
python3-concurrency
Python3爬虫系列的理论验证,首先研究I/O模型,分别用Python实现了blocking I/O、nonblocking I/O、I/O multiplexing各模型下的TCP服务端和客户端。然后,研究同步I/O操作(依序下载、多进程并发、多线程并发)和异步I/O(asyncio)之间的效率差别
Stars: ✭ 49 (-26.87%)
Mutual labels:  requests
PT-Tracking
Aplicação para registo e acompanhamento de encomendas da CTT Expresso, automatiza a consulta online do estado de tracking para várias remessas e mantém um registo dos pagamentos referentes aos envios à cobrança. As remessas que requerem atenção, devido a atrasos na entrega ou na receção do pagamento correspondente, bem como os cheques cuja data …
Stars: ✭ 18 (-73.13%)
Mutual labels:  requests
usim800
usim800 is a Python driver module for SIM800 GSM/GPRS .
Stars: ✭ 36 (-46.27%)
Mutual labels:  requests
cpr
C++ Requests: Curl for People, a spiritual port of Python Requests.
Stars: ✭ 5,005 (+7370.15%)
Mutual labels:  requests
web full stack application
show full stack technology applications : Scrapy + webservice[restful] + websocket + VueJS + MongoDB
Stars: ✭ 16 (-76.12%)
Mutual labels:  requests
weibo topic
微博话题关键词,个人微博采集, 微博博文一键删除 selenium获取cookie,requests处理
Stars: ✭ 28 (-58.21%)
Mutual labels:  requests
resto
🔗 a CLI app can send pretty HTTP & API requests with TUI
Stars: ✭ 113 (+68.66%)
Mutual labels:  requests
python-crawler
爬虫学习仓库,适合零基础的人学习,对新手比较友好
Stars: ✭ 37 (-44.78%)
Mutual labels:  requests
Tieba-Birthday-Spider
百度贴吧生日爬虫,可抓取贴吧内吧友生日,并且在对应日期自动发送祝福
Stars: ✭ 28 (-58.21%)
Mutual labels:  requests
get LibSeat
利昂图书馆预约系统自动预约&签到程序。支持包括中国人民大学、北京师范大学、济南大学、哈尔滨工业大学等在内的38所高校的图书馆系统
Stars: ✭ 39 (-41.79%)
Mutual labels:  requests
covid-19
Data ETL & Analysis on the global and Mexican datasets of the COVID-19 pandemic.
Stars: ✭ 14 (-79.1%)
Mutual labels:  requests
TeslaPy
A Python module to use the Tesla Motors Owner API
Stars: ✭ 216 (+222.39%)
Mutual labels:  requests
Geolocator-2
Learn how to find and work with locations in Django, the Yelp API, and Google Maps api.
Stars: ✭ 24 (-64.18%)
Mutual labels:  requests
TSdownloader
Template for downloading segmented video (.m3u8/.ts) from streaming websites
Stars: ✭ 17 (-74.63%)
Mutual labels:  requests
mkm-sdk
Python SDK for Magickartenmarkt API
Stars: ✭ 33 (-50.75%)
Mutual labels:  requests
Email-Crawler-Lead-Generator
This email crawler will visit all pages of a provided website and parse and save emails found to a csv file.
Stars: ✭ 47 (-29.85%)
Mutual labels:  requests
crawler
requests+lxml爬虫,简单爬虫架构
Stars: ✭ 72 (+7.46%)
Mutual labels:  requests
gists
Methods for working with the GitHub Gist API. Node.js/JavaScript
Stars: ✭ 96 (+43.28%)
Mutual labels:  requests

requests

http requests lib for golang

Features

  • GETPOSTPUTDELETE(Common HTTP methods)
  • application/jsonapplication/x-www-form-urlencodedmultipart/form-data
  • Global Request Interceptor

Examples

Get

func getText() {
	text, err := requests.Get("http://127.0.0.1:8080/ping").
		Params(url.Values{
			"param1": {"value1"},
			"param2": {"123"},
		}).
		Send().
		Text()
	if err != nil {
		panic(err)
	}
	fmt.Println(text)
}

query

GET http://127.0.0.1:8080/ping?param1=value1&param2=123 HTTP/1.1

Post Form

func postForm() {
	text, err := requests.Post("http://127.0.0.1:8080/ping").
		Params(url.Values{
			"param1": {"value1"},
			"param2": {"123"},
		}).
		Form(url.Values{
			"form1": {"value1"},
			"form2": {"123"},
		}).
		Send().
		Text()
	if err != nil {
		panic(err)
	}
	fmt.Println(text)
}

post form

POST http://127.0.0.1:8080/ping?param1=value1&param2=123 HTTP/1.1
Content-Type: application/x-www-form-urlencoded

form1=value1&form2=123

Post Json

func postJson() {
	text, err := requests.Post("http://127.0.0.1:8080/ping").
		Params(url.Values{
			"param1": {"value1"},
			"param2": {"123"},
		}).
		Json(map[string]interface{}{
			"json1": "value1",
			"json2": 2,
		}).
		Send().
		Text()
	if err != nil {
		panic(err)
	}
	fmt.Println(text)
}

post json

POST http://127.0.0.1:8080/ping?param1=value1&param2=123 HTTP/1.1
Content-Type: application/json

{"json1": "value1", "json2": 2}

Post Multipart

func postMultipart() {
	text, err := requests.Post("http://127.0.0.1:8080/ping").
		Params(url.Values{
			"param1": {"value1"},
			"param2": {"123"},
		}).
		Multipart(requests.FileForm{
			Value: url.Values{
				"form1": {"value1"},
				"form2": {"value2"},
			},
			File: map[string]string{
				"file1": "./examples/main.go",
				"file2": "./examples/main.go",
			},
		}).
		Send().
		Text()
	if err != nil {
		panic(err)
	}
	fmt.Println(text)
}

post multipart/form-data

POST http://127.0.0.1:8080/ping?param1=value1&param2=123 HTTP/1.1
Content-Type: multipart/form-data; boundary=947f4ca12d44786ccda8f8cd60e083fca2ec1ede6d8f1bad69f4cf03bc8a

--947f4ca12d44786ccda8f8cd60e083fca2ec1ede6d8f1bad69f4cf03bc8a
Content-Disposition: form-data; name="file1"; filename="./examples/main.go"
Content-Type: application/octet-stream

bytes...

--947f4ca12d44786ccda8f8cd60e083fca2ec1ede6d8f1bad69f4cf03bc8a
Content-Disposition: form-data; name="file2"; filename="./examples/main.go"
Content-Type: application/octet-stream

bytes...

--947f4ca12d44786ccda8f8cd60e083fca2ec1ede6d8f1bad69f4cf03bc8a
Content-Disposition: form-data; name="form1"

value1
--947f4ca12d44786ccda8f8cd60e083fca2ec1ede6d8f1bad69f4cf03bc8a
Content-Disposition: form-data; name="form2"

value2
--947f4ca12d44786ccda8f8cd60e083fca2ec1ede6d8f1bad69f4cf03bc8a--

Save File

func save() {
	err := requests.Get("https://github.com/xuanbo/requests").
		Send().
		Save("./requests.html")
	if err != nil {
		panic(err)
	}
}

Check Status Code

func save() {
	err := requests.Get("https://github.com/xuanbo/requests").
		Send().
		// resp status code must be 200.
		StatusOk().
		Save("./requests.html")
	if err != nil {
		panic(err)
	}
}
  • StatusOk()
  • Status2xx()

Custom Http

func customHttp() {
	client := &http.Client{
		Timeout: 5 * time.Second,
	}
	text, err := requests.Request("https://github.com/xuanbo", "OPTIONS", client).
		Send().
		Text()
	if err != nil {
		panic(err)
	}
	fmt.Println(text)
}

Global Request Interceptor

func requestInterceptor() {
	logRequestInterceptor := func(request *http.Request) error {
		fmt.Println(request.URL)
		return nil
	}
	requests.AddRequestInterceptors(logRequestInterceptor)

	text, err := requests.Get("https://github.com/xuanbo").
		Send().
		Text()
	if err != nil {
		panic(err)
	}
	fmt.Println(text)
}
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].