Implement method_map in middleware function