repositorypackage
0.0.0-20181130164953-01d4f75b29bd
Repository: https://github.com/pmoneda/http.git
Documentation: pkg.go.dev
# Packages
No description provided by the author
# README
http
Http wrapper over default http library with high level abstraction and mock capabilities
Install
- go get
$ go get github.com/PMoneda/http
- dep
dep ensure -add github.com/PMoneda/http
Examples
GET Request
package main
import (
"github.com/PMoneda/http"
"fmt"
)
func main() {
response, _ := http.Get("http://my-awesome-api.com");
fmt.Println(response)
}
POST Request with headers
package main
import (
"github.com/PMoneda/http"
"fmt"
)
func main() {
body := struct {
ID string
}{ID:"my-id"}
response, _ := http.Post("http://my-awesome-api.com", body, http.Header{Key: "Content-Type", Value: "application/x-www-form-urlencoded"});
fmt.Println(response)
}
Simple POST Request
package main
import (
"github.com/PMoneda/http"
"fmt"
)
func main() {
body := struct {
ID string
}{ID:"my-id"}
response, _ := http.Post("http://my-awesome-api.com", body);
fmt.Println(response)
}
Testing with http Mock
func TestShouldRequestToAwesomeAPI(t *testing.T) {
mock := http.ReponseMock{
Method: "POST",
}
http.With(t, func(ctx *http.MockContext) {
ctx.RegisterMock(&mock)
response, err := http.Post("http://some-url","body")
if err != nil {
t.Fail()
}
})
}