https://github.com/adhityaramadhanus/httpstub
A wrapper package for an easier way to stub http request in golang
https://github.com/adhityaramadhanus/httpstub
Last synced: 2 months ago
JSON representation
A wrapper package for an easier way to stub http request in golang
- Host: GitHub
- URL: https://github.com/adhityaramadhanus/httpstub
- Owner: AdhityaRamadhanus
- License: gpl-3.0
- Created: 2019-08-19T16:17:36.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-07T14:35:55.000Z (over 5 years ago)
- Last Synced: 2025-02-05T07:15:46.551Z (4 months ago)
- Language: Go
- Size: 30.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# httpstub
A wrapper package for an easier way to stub http request in golangExamples
-----
* see godoc for more detailed examples
```go
srv := httpstub.NewStubServer()
srv.StubRequest(http.MethodGet, "/healthz")
defer srv.Close()url := fmt.Sprintf("%s%s", srv.URL(), "/healthz")
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
panic(err)
}resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
respBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}fmt.Printf("Response Body: %s\n", string(respBody))
fmt.Printf("Response Status Code: %d\n", resp.StatusCode)// Output:
// Response Body: OK
// Response Status Code: 200
}
```License
----GPL © [Adhitya Ramadhanus]