https://github.com/rodkranz/fetch
Golang Fetch
https://github.com/rodkranz/fetch
golang golang-examples golang-http golang-package golang-tools
Last synced: 3 months ago
JSON representation
Golang Fetch
- Host: GitHub
- URL: https://github.com/rodkranz/fetch
- Owner: rodkranz
- License: mit
- Created: 2017-10-13T14:33:14.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-02-07T09:26:47.000Z (over 5 years ago)
- Last Synced: 2024-09-29T21:21:38.519Z (10 months ago)
- Topics: golang, golang-examples, golang-http, golang-package, golang-tools
- Language: Go
- Size: 39.1 KB
- Stars: 11
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/rodkranz/fetch)
[](https://godoc.org/github.com/rodkranz/fetch)
[](https://raw.githubusercontent.com/rodkranz/fetch/master/LICENSE)
[](https://goreportcard.com/report/github.com/rodkranz/fetch)
# Fetch HTTP ClientSimple fetch made in Go to simplify the life of programmer.
## About
Go’s http package doesn’t specify request timeouts by default, allowing services to hijack your goroutines. **Always specify a custom http.Client** when connecting to outside services.## Install
> Default
```shell
go get github.com/rodkranz/fetch
```> [Go DEP](https://github.com/golang/dep)
```shell
dep ensure --add github.com/rodkranz/fetch
```## Import
```go
import (
"github.com/rodkranz/fetch"
)
```## Test
To run the project test```shell
go test -v --cover
```## Example:
#### Simple
```go
client := fetch.NewDefault()
response, err := client.Get("http://www.google.com/", nil)
```#### Custom Headers
```go
opt := fetch.Options{
Header: http.Header{
"Content-Type": []string{"application/json"},
"User-Agent": []string{"XPTO-Agent-user"},
},
}f := fetch.New(&opt)
rsp, err := f.GetWithContext(context.Background(), "http://www.google.com", nil)
```#### Simple JSON POST
```go
login := map[string]interface{}{
"username": "rodkranz",
"password": "loremIpsum",
}
response, err := fetch.NewDefault().
IsJSON().
Post("http://www.google.com/", fetch.NewReader(login))
```