Extract request logic from api endpoint