Files
micromdm/platform/device/server.go
jenjac 3370b9cb11 GET to POST (#522)
Changed GET to POST as a GET with a request body is not preferred.
2018-10-10 12:32:02 -04:00

41 lines
1.2 KiB
Go

package device
import (
"github.com/go-kit/kit/endpoint"
httptransport "github.com/go-kit/kit/transport/http"
"github.com/gorilla/mux"
"github.com/micromdm/micromdm/pkg/httputil"
)
type Endpoints struct {
ListDevicesEndpoint endpoint.Endpoint
RemoveDevicesEndpoint endpoint.Endpoint
}
func MakeServerEndpoints(s Service, outer endpoint.Middleware, others ...endpoint.Middleware) Endpoints {
return Endpoints{
ListDevicesEndpoint: endpoint.Chain(outer, others...)(MakeListDevicesEndpoint(s)),
RemoveDevicesEndpoint: endpoint.Chain(outer, others...)(MakeRemoveDevicesEndpoint(s)),
}
}
func RegisterHTTPHandlers(r *mux.Router, e Endpoints, options ...httptransport.ServerOption) {
// POST /v1/devices get a list of devices managed by the server
// DELETE /v1/devices remove one or more devices from the server
r.Methods("POST").Path("/v1/devices").Handler(httptransport.NewServer(
e.ListDevicesEndpoint,
decodeListDevicesRequest,
httputil.EncodeJSONResponse,
options...,
))
r.Methods("DELETE").Path("/v1/devices").Handler(httptransport.NewServer(
e.RemoveDevicesEndpoint,
decodeRemoveDevicesRequest,
httputil.EncodeJSONResponse,
options...,
))
}