Refactor how api endpoints are built