
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
github.com/ricardogama/api-mocker-go
Advanced tools
Go SDK for api-mocker
Install the package via go get or add to your dependency manager file:
$ go get github.com/ricardogama/api-mocker-go
Create a new mocker and use its sugar functions to communicate with the mocker server:
package main
import (
"fmt"
"net/http"
"github.com/ricardogama/api-mocker-go"
)
func main() {
mock := mocker.New("http://localhost:3000")
defer mock.Clear() // DELETE /mocks
// POST /mocks
err := mock.Expect(&mocker.Request{
Method: "POST",
Path: "/foo",
Body: map[string]interface{}{
"foo": "bar",
},
Headers: map[string]string{
"X-User-ID": "1",
},
Response: &mocker.Response{
Status: 200,
Headers: map[string]string{
"Content-Range": "bytes 200-1000/67589",
},
Body: map[string]interface{}{
"qux": "qix",
},
},
})
if err != nil {
panic(err)
}
_, err := http.Get("http://localhost:3000/foo")
if err != nil {
panic(err)
}
// GET /mocks, returning an error if there's unexpected requests.
err := mock.Ensure()
fmt.Println(err)
// missing 1 expected calls: [
// {
// "headers": {
// "X-User-ID": "1"
// },
// "body": {
// "foo": "bar"
// },
// "method": "POST",
// "path": "/foo",
// "response": {
// "headers": {
// "Content-Range": "bytes 200-1000/67589"
// },
// "body": {
// "qux": "qix"
// },
// "status": 200
// }
// }
// ]
// 1 unexpected calls: [
// {
// "headers": {
// "accept-encoding": "gzip",
// "host": "localhost:3005",
// "user-agent": "Go-http-client/1.1"
// },
// "body": {},
// "method": "GET",
// "path": "/foo",
// "response": null
// }
// ]
})
}
FAQs
Unknown package
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.