Example #1
0
// RESTRoutes implements the rest.Routable interface which is used by
// rest.Endpoint to route incoming HTTP request to the appropriate handler.
func (svc *PingService) RESTRoutes() rest.Routes {

	return rest.Routes{

		// Route with no arguments provided in the path means that the argument
		// required by Ping will be taken from the body of the HTTP request. The
		// body is assumed to be JSON and will automatically be unmarshalled.
		//
		// The function's return value will be automatically serialized to JSON
		// using the encoding.json package and used as the body of the HTTP
		// response sent to the client. If nothing or nil is returned then an
		// HTTP 204 response code is returned instead.
		rest.NewRoute("/ping", "POST", svc.Ping),

		// Path components starting with ':' indicates that the first argument
		// of the Ping function will be fed from the value found where the
		// placeholder is in the path.
		//
		// Path arguments are assumed to be basic types (string, bool, int
		// floats) and are automatically converted to match the function
		// argument.
		rest.NewRoute("/ping/:tick", "PUT", svc.Ping),

		// We can also return errors which will automatically be detected and
		// converted to a HTTP 400 return code to the user. The HTTP return code
		// can be changed by returning a rest.CodedError.
		//
		// The body is returned as a simple string containing the string
		// representation of the error object.
		rest.NewRoute("/ping/error", "POST", svc.PingError),
	}
}
Example #2
0
// RESTRoutes returns the list of REST routes.
func (handler *RESTHandler) RESTRoutes() rest.Routes {
	prefix := handler.PathPrefix
	if prefix == "" {
		prefix = DefaultPathREST + "/keys"
	}

	return []*rest.Route{
		rest.NewRoute(prefix, "GET", handler.Get),
		rest.NewRoute(prefix+"/prefix/:substr", "GET", handler.GetPrefix),
		rest.NewRoute(prefix+"/substr/:substr", "GET", handler.GetSubstr),
		rest.NewRoute(prefix+"/pattern/:pattern", "GET", handler.GetPattern),
	}
}
Example #3
0
// RESTRoutes returns the set of gorest routes used to manipulate the Ring
// printer.
func (ring *RingREST) RESTRoutes() rest.Routes {
	prefix := ring.PathPrefix
	if len(prefix) == 0 {
		prefix = DefaultPathREST + "/ring"
	}

	return []*rest.Route{
		rest.NewRoute(prefix, "GET", ring.GetAll),
		rest.NewRoute(prefix+"/key/:key", "GET", ring.GetKey),
		rest.NewRoute(prefix+"/prefix/:prefix", "GET", ring.GetPrefix),
		rest.NewRoute(prefix+"/suffix/:suffix", "GET", ring.GetSuffix),
	}
}
Example #4
0
// RESTRoutes returns the set of gorest routes used to manipulate the Filter
// chained printer.
func (filter *FilterREST) RESTRoutes() rest.Routes {
	prefix := filter.PathPrefix
	if len(prefix) == 0 {
		prefix = DefaultPathREST + "/filter"
	}

	return []*rest.Route{
		rest.NewRoute(prefix, "GET", filter.Get),

		rest.NewRoute(prefix+"/key/:key", "PUT", filter.add),
		rest.NewRoute(prefix+"/key/:key", "DELETE", filter.remove),

		rest.NewRoute(prefix+"/prefix/:prefix", "PUT", filter.addPrefix),
		rest.NewRoute(prefix+"/prefix/:prefix", "DELETE", filter.removePrefix),

		rest.NewRoute(prefix+"/suffix/:suffix", "PUT", filter.addSuffix),
		rest.NewRoute(prefix+"/suffix/:suffix", "DELETE", filter.removeSuffix),
	}
}