https://github.com/hantmac/simple-httpclient
Simple Http request lib, easy to do GET、POST, etc.
https://github.com/hantmac/simple-httpclient
Last synced: about 12 hours ago
JSON representation
Simple Http request lib, easy to do GET、POST, etc.
- Host: GitHub
- URL: https://github.com/hantmac/simple-httpclient
- Owner: hantmac
- License: apache-2.0
- Created: 2018-11-22T08:13:59.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-26T09:54:25.000Z (about 7 years ago)
- Last Synced: 2025-01-18T10:27:37.104Z (11 months ago)
- Language: Go
- Size: 16.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
**simpleHttpClient help you do http request easily**
* usage:
go get github.com/hantmac/simple-httpClient
- Use simpleHttpClient you have no need to concern about handling error response or check the status code.
- You can use the lib flow the next example
```
headers := map[string]string{
{"Content-type": "application/json"},
}
resp,header,err := simpleHttpClient.DoRequest("GET", "https://api.github.com/events", headers, nil, 10)
```
- That means the action you use to do request is GET, and the URL is "https://api.github.com/events",the headers of the request is a map which is {"Content-type": "application/json"}, the body for this request is nil(If you need the request body,see the next step), and finally you can add a number represent the time that you want to wait, if timeout, report an error.
### Use body
- if your request body is not empty, you can add and configure your body like this:
- create a request body struct:
```
type requestBody struct {
ID string
name string
}
```
- New a object of request body
```
cb := &requestBody{}
```
- Add paramters to body
```
cb.ID = "test"
cb.name = "jack"
```
- marshal struct to []byte
```
body, err := json.Marshal(cb)
```
- Finally you can use your request body like:
```
resp, err : = simpleHttpClient.DoRequest("POST", 'http://httpbin.org/post', headers, body, timeoutSeconds)
```