https://github.com/ddo/request
:pizza: Simplified HTTP request client in go
https://github.com/ddo/request
golang http http-client request
Last synced: 13 days ago
JSON representation
:pizza: Simplified HTTP request client in go
- Host: GitHub
- URL: https://github.com/ddo/request
- Owner: ddo
- License: mit
- Created: 2015-03-06T18:48:15.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2017-10-24T17:02:24.000Z (over 8 years ago)
- Last Synced: 2025-08-31T08:51:35.170Z (5 months ago)
- Topics: golang, http, http-client, request
- Language: Go
- Homepage:
- Size: 33.2 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# request [![Build Status][semaphoreci-img]][semaphoreci-url] [![Doc][godoc-img]][godoc-url]
> Simplified HTTP request client in go
[godoc-img]: https://img.shields.io/badge/godoc-Reference-brightgreen.svg?style=flat-square
[godoc-url]: https://godoc.org/gopkg.in/ddo/request.v1
[semaphoreci-img]: https://semaphoreci.com/api/v1/projects/fe48ba6a-f987-4018-b778-34c0fef12c87/620801/badge.svg
[semaphoreci-url]: https://semaphoreci.com/ddo/request
## installation
```shell
go get gopkg.in/ddo/request.v1
```
## option
* URL ``string`` required
* Method ``string`` default: "GET", anything "POST", "PUT", "DELETE" or "PATCH"
* BodyStr ``string``
* Body ``*Data``
* Form ``*Data`` set Content-Type header as "application/x-www-form-urlencoded"
* JSON ``interface{}`` set Content-Type header as "application/json"
* Query ``*Data``
* Header ``*Header``
### GET
```go
client := request.New()
data, res, err := client.Request(&request.Option{
URL: "https://httpbin.org/get",
})
if err != nil {
panic(err)
}
```
### POST
```go
data, res, err := client.Request(&request.Option{
URL: "https://httpbin.org/post",
Method: "POST",
Body: &request.Data{
"two": []string{"2", "hai"},
"three": []string{"3", "ba", "trois"},
"email": []string{"ddo@ddo.me"},
},
})
```
### POST form
```go
data, res, err := client.Request(&request.Option{
URL: "https://httpbin.org/post",
Method: "POST",
Form: &request.Data{
"two": []string{"2", "hai"},
"three": []string{"3", "ba", "trois"},
"email": []string{"ddo@ddo.me"},
},
})
```
### JSON
```go
data, res, err := client.Request(&request.Option{
URL: "https://httpbin.org/post",
Method: "POST",
JSON: map[string]interface{}{
"int": 1,
"string": "two",
"array": []string{"3", "ba", "trois"},
"object": map[string]interface{}{
"int": 4,
},
},
})
```
## logger
to enable log set environment variable as
```shell
DLOG=*
```
or
```shell
DEBUG=* go run file.go
```
## test
```shell
go test -v
```
## TODO
* default settings
* hooks
* file