Added middleware for api requests