code: func getEventByDeviceHandler(w http.ResponseWriter, r *http.Request) {
  	defer r.Body.Close()
  
  	vars := mux.Vars(r)
  	limit := vars["limit"]
  	ctx := r.Context()
  	deviceId, err := url.QueryUnescape(vars["deviceId"])
  
  	// Problems unescaping URL
  	if err != nil {
  		http.Error(w, err.Error(), http.StatusBadRequest)
  		LoggingClient.Error("Error unescaping URL: " + err.Error())
  		return
  	}
  
  	// Convert limit to int
  	limitNum, err := strconv.Atoi(limit)
  	if err != nil {
  		http.Error(w, err.Error(), http.StatusBadRequest)
  		LoggingClient.Error("Error converting to integer: " + err.Error())
  		return
  	}
  
  	// Check device
  	if err := checkDevice(deviceId, ctx); err != nil {
  		LoggingClient.Error(fmt.Sprintf("error checking device %s %v", deviceId, err))
  		switch err := err.(type) {
  		case *types.ErrServiceClient:
  			http.Error(w, err.Error(), err.StatusCode)
  			return
  		default: //return an error on everything else.
  			http.Error(w, err.Error(), http.StatusServiceUnavailable)
  			return
  		}
  	}
  
  	switch r.Method {
  	case http.MethodGet:
  		err := checkMaxLimit(limitNum)
  		if err != nil {
  			http.Error(w, maxExceededString, http.StatusRequestEntityTooLarge)
  			return
  		}
  
  		eventList, err := getEventsByDeviceIdLimit(limitNum, deviceId)
  
  		if err != nil {
  			http.Error(w, err.Error(), http.StatusInternalServerError)
  			return
  		}
  
  		encode(eventList, w)
  	}
  }
docs: // Get event by device id
  // Returns the events for the given device sorted by creation date and limited by 'limit'
  // {deviceId} - the device that the events are for
  // {limit} - the limit of events
  // api/v1/event/device/{deviceId}/{limit}