Moved network code into API client