refactor so there's more code reuse in js request code.