An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

        

# httpstub
A wrapper package for an easier way to stub http request in golang


Examples |
License



Examples
-----
* 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]