https://github.com/davidji99/simpleresty
A light wrapper around go-resty
https://github.com/davidji99/simpleresty
api-client api-rest go-restful go-resty golang
Last synced: 4 months ago
JSON representation
A light wrapper around go-resty
- Host: GitHub
- URL: https://github.com/davidji99/simpleresty
- Owner: davidji99
- License: mit
- Created: 2020-03-07T02:35:02.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-03-18T08:34:09.000Z (about 1 year ago)
- Last Synced: 2025-01-31T19:29:34.628Z (4 months ago)
- Topics: api-client, api-rest, go-restful, go-resty, golang
- Language: Go
- Homepage:
- Size: 1.01 MB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/davidji99/simpleresty/actions)
[](https://goreportcard.com/report/github.com/davidji99/simpleresty)A simple wrapper around [go-resty](https://github.com/go-resty/resty).
## Background
Having used [go-resty](https://github.com/go-resty/resty) to create clients for various service APIs,
I noticed a common set of methods/functions I would define in each API client. I extracted those methods/functions
and moved them into this separate library. This way, all my clients could benefit from using a single library to
interface with the APIs.I have embedded `resty.Client` into `simpleresty.Client` so all of `resty`'s functions/methods are available to the user.
In fact, `simpleresty.New()` returns a `resty.Client`.## Example
```go
package mainimport (
"fmt"
"github.com/davidji99/simpleresty"
)type GithubAPIResponse struct {
CurrentUserURL string `json:"current_user_url,omitempty"`
}func main() {
c := simpleresty.New()var result *GithubAPIResponse
response, getErr := c.Get("https://api.github.com", &result, nil)
if getErr != nil {
panic(getErr)
}fmt.Println(response.StatusCode) // Returns 200
fmt.Println(result.CurrentUserURL) // Returns 'https://api.github.com/user'
}
```Additional examples can be found in the `/examples` folder.
You can also check out [rollrest-go](https://github.com/davidji99/rollrest-go), which uses this library to implement
an API rest client for Rollbar.## Proxy
`simpleresty` respects any proxy URLs set in your environment in this order of preference:
1. `HTTPS_PROXY`
1. `https_proxy`
1. `HTTP_PROXY`
1. `http_proxy`Only a single value from one of the above four environment variables will be used to set the proxy URL on the `Client`.
`simpleresty` will also respect domains (not IP addresses or CIDR ranges) defined by the `NO_PROXY` or `no_proxy`
environment variable. Multiple domains must be separated by a comma.## Go-Resty
As this pkg is a thin wrapper around go-resty, all of its methods are available to use in this package.
Please refer to [go-resty's documentation](https://github.com/go-resty/resty) for more information.