Skip to content

Latest commit

 

History

History
85 lines (65 loc) · 3.98 KB

README.md

File metadata and controls

85 lines (65 loc) · 3.98 KB

HTTP Mama

Utility library for various HTTP related task in Golang





Usage

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!"
}

Documentation

Full documentation is available on pkg.go.dev/github.com/shahariaazam/httpmama

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.