modulizing some of the api function and making it middleware