Refactored to use a DRY-er way of defining the api endpoints