{"action":"closed","issue":{"url":"https://api.github.com/repos/visionmedia/superagent/issues/830","repository_url":"https://api.github.com/repos/visionmedia/superagent","labels_url":"https://api.github.com/repos/visionmedia/superagent/issues/830/labels{/name}","comments_url":"https://api.github.com/repos/visionmedia/superagent/issues/830/comments","events_url":"https://api.github.com/repos/visionmedia/superagent/issues/830/events","html_url":"https://github.com/visionmedia/superagent/issues/830","id":124979435,"number":830,"title":"API consistency and code sharing","user":{"login":"focusaurus","id":482377,"avatar_url":"https://avatars.githubusercontent.com/u/482377?v=3","gravatar_id":"","url":"https://api.github.com/users/focusaurus","html_url":"https://github.com/focusaurus","followers_url":"https://api.github.com/users/focusaurus/followers","following_url":"https://api.github.com/users/focusaurus/following{/other_user}","gists_url":"https://api.github.com/users/focusaurus/gists{/gist_id}","starred_url":"https://api.github.com/users/focusaurus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/focusaurus/subscriptions","organizations_url":"https://api.github.com/users/focusaurus/orgs","repos_url":"https://api.github.com/users/focusaurus/repos","events_url":"https://api.github.com/users/focusaurus/events{/privacy}","received_events_url":"https://api.github.com/users/focusaurus/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":{"login":"focusaurus","id":482377,"avatar_url":"https://avatars.githubusercontent.com/u/482377?v=3","gravatar_id":"","url":"https://api.github.com/users/focusaurus","html_url":"https://github.com/focusaurus","followers_url":"https://api.github.com/users/focusaurus/followers","following_url":"https://api.github.com/users/focusaurus/following{/other_user}","gists_url":"https://api.github.com/users/focusaurus/gists{/gist_id}","starred_url":"https://api.github.com/users/focusaurus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/focusaurus/subscriptions","organizations_url":"https://api.github.com/users/focusaurus/orgs","repos_url":"https://api.github.com/users/focusaurus/repos","events_url":"https://api.github.com/users/focusaurus/events{/privacy}","received_events_url":"https://api.github.com/users/focusaurus/received_events","type":"User","site_admin":false},"milestone":null,"comments":6,"created_at":"2016-01-05T14:41:12Z","updated_at":"2016-03-26T20:46:43Z","closed_at":"2016-03-26T20:46:43Z","body":"There are numerous open issues noting discrepancies in either API or implementation between the browser and node codebases. I've done a comprehensive review of the public API (at least for methods if not all events). Posting here for review and discussion. Should we extract a module (commonjs file, not a separate npm package) of shared code? If so, how would the documentation work? Should we refactor code to be shared when it's 98% similar already and technically possible to do so?\r\n\r\n- [x] `request(method, url)`: duplicated, refactor\r\n- [x] `req.timeout(ms)`: duplicated, refactor\r\n- [x] `req.clearTimeout(ms)`: duplicated, refactor\r\n- [x] `req.use(fn)`: duplicated, refactor\r\n- [x] `req.then(fn)`: duplicated. refactor\r\n- [x] `req.parse(fn)`: duplicated, refactor\r\n- [x] `req.set(name, value)`: slight difference, refactor to shared if possible\r\n- [x] `req.getHeader(name)`: slight difference, refactor to shared if possible\r\n- [x] `req.unset(name, value)`: slight difference, refactor to shared if possible\r\n- [x] `req.field(name, value)`: slight difference, refactor to shared if possible\r\n- [x] `req.abort()`: slight difference, extract base function and extend in subclasses\r\n- [x] `req.withCredentials()`: browser-only API. Node could be no-op stub I think\r\n- [x] `req.send(body)`: slight difference, refactor to shared if possible\r\n- [x] `req.toJSON()`: node only. Refactor to shared?\r\n- [ ] `req.query(value)`: slight difference, refactor to shared if possible\r\n- [ ] `progress event`: see issues #807 and #803\r\n- [ ] `req.get(url, data, fn)` and other HTTP methods: lots of duplication here. Refactor\r\n  - node side supports a lot more HTTP verbs from the \"methods\" npm package\r\n- [ ] `req.type(value)`: slight difference, refactor to shared if possible\r\n- [ ] `req.accept(value)`: slight difference, refactor to shared if possible\r\n  - for both `.type()` and `.accept()` the node side uses `mime` for dubious benefit\r\n  - currently debating removing mime dependency and keeping it to the 6 aliases the client code supports, OR just leaving the code as is\r\n\r\nThe following code has been reviewed and is OK as is:\r\n\r\n- `req.auth(user, password)`: different implementations. Slight API difference. OK.\r\n- `request.Request(method, url)`: same API, different code, OK\r\n- `req.attach(field, file, filename)`: same API, different code, OK\r\n- `req.end(fn)`: same API, different code, OK\r\n- `req.pipe(stream)`: node only, OK\r\n- `req.write(chunk)`: node only, OK\r\n- `req.redirects(number)`: node only, OK\r\n- `req.agent(agent)`: node only, OK\r\n- `req.buffer(flag)`: node only, OK\r\n- `req.ca(cert)`: node only, OK"}}