func (a *apiHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	bsize := handler.DefaultMaxRecvSize
	if a.opts.MaxRecvSize > 0 {
		bsize = a.opts.MaxRecvSize
	}
	r.Body = http.MaxBytesReader(w, r.Body, bsize)
	request, err := requestToProto(r)
	if err != nil {
		er := errors.InternalServerError("go.micro.api", err.Error())
		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(500)
		w.Write([]byte(er.Error()))
		return
	}
	var service *goapi.Service
	if a.s != nil {
		service = a.s
	} else if a.opts.Router != nil {
		s, err := a.opts.Router.Route(r)
		if err != nil {
			er := errors.InternalServerError("go.micro.api", err.Error())
			w.Header().Set("Content-Type", "application/json")
			w.WriteHeader(500)
			w.Write([]byte(er.Error()))
			return
		}
		service = s
	} else {
		er := errors.InternalServerError("go.micro.api", "no route found")
		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(500)
		w.Write([]byte(er.Error()))
		return
	}
	c := a.opts.Client
	req := c.NewRequest(service.Name, service.Endpoint.Name, request)
	rsp := &api.Response{}
	cx := ctx.FromRequest(r)
	if err := c.Call(cx, req, rsp, client.WithRouter(router.New(service.Services))); err != nil {
		w.Header().Set("Content-Type", "application/json")
		ce := errors.Parse(err.Error())
		switch ce.Code {
		case 0:
			w.WriteHeader(500)
		default:
			w.WriteHeader(int(ce.Code))
		}
		w.Write([]byte(ce.Error()))
		return
	} else if rsp.StatusCode == 0 {
		rsp.StatusCode = http.StatusOK
	}
	for _, header := range rsp.GetHeader() {
		for _, val := range header.Values {
			w.Header().Add(header.Key, val)
		}
	}
	if len(w.Header().Get("Content-Type")) == 0 {
		w.Header().Set("Content-Type", "application/json")
	}
	w.WriteHeader(int(rsp.StatusCode))
	w.Write([]byte(rsp.Body))
}
API handler is the default handler which takes api.Request and returns api.Response
package api
import (
	"net/http"
	api "github.com/micro/micro/v3/proto/api"
	goapi "github.com/micro/micro/v3/service/api"
	"github.com/micro/micro/v3/service/api/handler"
	"github.com/micro/micro/v3/service/client"
	"github.com/micro/micro/v3/service/errors"
	"github.com/micro/micro/v3/util/ctx"
	"github.com/micro/micro/v3/util/router"
)
type apiHandler struct {
	opts handler.Options
	s    *goapi.Service
}
const (
	Handler = "api"
)