add pass_api_config method and refactored api codes.

Add pass_api_config method and refactored duplicate codes on api.