This package contains helpers for quickly spinning up a fake API server (using `net/http/httptest`), testing the incoming request (using the great JSON tools from ``), and responding with certain values.

It is meant to be used in tests to mock the "other end" of an HTTP request to get as close to full integration tests as possible without actually relying on an external service.

# Usage
Check the documentation of [httpexpect.Value]( for what to do with the result of `JSONBody()`.


import (

func TestMyPackage(t *testing.T) {
  mockAPIServer := apimocker.NewServer(t)

  mockAPIServer.On("GET", "/foo/bar", func(req *apimocker.Request) {
    // Check the header
    req.ExpectHeader("Content-Type", "application/json")

    // Check the body?

    // Respond
    req.Respond().WithStatus(200).WithHeader("Content-Type", "application/json").WithJSON(apimocker.H{
      "status": "ok",

  url := mockAPIServer.Start()
  defer mockAPIServer.Stop()

  // Now hit the API!

Imports 2 package(s) ΒΆ