Extract out logic of building api host