[api] Extract the connection factory to it's own method