Moved the main logic to a BaseRestController.