Javascript: reffactor out API and ApiUrlBuilder classes