create api; move code to api.js;