Utility library for various HTTP related task in Golang
go get github.com/shahariaazam/httpmama
package main
import (
"fmt"
"io/ioutil"
"net/http"
"github.com/shahariaazam/httpmama"
)
func main() {
endpoint1 := httpmama.TestEndpoint{
Path: "/foo",
ResponseString: "hello, world!",
ResponseHeader: http.Header{"Content-Type": []string{"text/plain"}},
}
endpoint2 := httpmama.TestEndpoint{
Path: "/bar",
ResponseString: "goodbye, world!",
ResponseHeader: http.Header{"Content-Type": []string{"text/plain"}},
}
config := httpmama.ServerConfig{
TestEndpoints: []httpmama.TestEndpoint{endpoint1, endpoint2},
}
// Create the server
server := httpmama.NewTestServer(config)
defer server.Close()
// Start making request to the server
resp, err := http.Get(server.URL + "/foo")
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(body)) // Output: "hello, world!"
}
Full documentation is available on pkg.go.dev/github.com/shahariaazam/httpmama
This project is licensed under the MIT License - see the LICENSE file for details.