{"action":"created","issue":{"url":"https://api.github.com/repos/mjackson/http-client/issues/34","repository_url":"https://api.github.com/repos/mjackson/http-client","labels_url":"https://api.github.com/repos/mjackson/http-client/issues/34/labels{/name}","comments_url":"https://api.github.com/repos/mjackson/http-client/issues/34/comments","events_url":"https://api.github.com/repos/mjackson/http-client/issues/34/events","html_url":"https://github.com/mjackson/http-client/issues/34","id":183241640,"number":34,"title":"Change default `as` in parse middleware","user":{"login":"agilgur5","id":4970083,"avatar_url":"https://avatars.githubusercontent.com/u/4970083?v=3","gravatar_id":"","url":"https://api.github.com/users/agilgur5","html_url":"https://github.com/agilgur5","followers_url":"https://api.github.com/users/agilgur5/followers","following_url":"https://api.github.com/users/agilgur5/following{/other_user}","gists_url":"https://api.github.com/users/agilgur5/gists{/gist_id}","starred_url":"https://api.github.com/users/agilgur5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agilgur5/subscriptions","organizations_url":"https://api.github.com/users/agilgur5/orgs","repos_url":"https://api.github.com/users/agilgur5/repos","events_url":"https://api.github.com/users/agilgur5/events{/privacy}","received_events_url":"https://api.github.com/users/agilgur5/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-10-16T00:41:01Z","updated_at":"2016-11-25T03:58:14Z","closed_at":null,"body":"Currently the default property for `as` is `body`, but the logic makes this undesirables, as:\n\nhttps://github.com/mjackson/http-client/blob/master/modules/index.js#L205\n\n```\n    if (as in response)\n      return response[as]\n```\n\nwill by default return `response.body`, which may already be populated.\n\nI run a response middleware after the parse usually, but using\n`parse('json'), recv(({body}) => body)`\nresults in `undefined` to be output.\n\nIf I instead use\n`parse('json', 'jsonData'), recv(({jsonData}) => jsonData)`,\nit works as intended, returning the JSON/JS Object.\n\nNot sure what a better name would be; perhaps `bodyData` sticking by previous conventions?\n"},"comment":{"url":"https://api.github.com/repos/mjackson/http-client/issues/comments/262876579","html_url":"https://github.com/mjackson/http-client/issues/34#issuecomment-262876579","issue_url":"https://api.github.com/repos/mjackson/http-client/issues/34","id":262876579,"user":{"login":"mjackson","id":92839,"avatar_url":"https://avatars.githubusercontent.com/u/92839?v=3","gravatar_id":"","url":"https://api.github.com/users/mjackson","html_url":"https://github.com/mjackson","followers_url":"https://api.github.com/users/mjackson/followers","following_url":"https://api.github.com/users/mjackson/following{/other_user}","gists_url":"https://api.github.com/users/mjackson/gists{/gist_id}","starred_url":"https://api.github.com/users/mjackson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjackson/subscriptions","organizations_url":"https://api.github.com/users/mjackson/orgs","repos_url":"https://api.github.com/users/mjackson/repos","events_url":"https://api.github.com/users/mjackson/events{/privacy}","received_events_url":"https://api.github.com/users/mjackson/received_events","type":"User","site_admin":false},"created_at":"2016-11-25T03:58:14Z","updated_at":"2016-11-25T03:58:14Z","body":"Hmm, I'm not sure why `parse('json')` would give you an `undefined` `response.body`. In that case, `response.body` should be the JSON payload.\r\n\r\nThe purpose of that `if` statement is to protect against you running, for example, `response.json()` twice on the same `response` because the second one will fail after the body is already used. So the first time it is used `response.body` would be set. And on the second time, you'd just get the previous result.\r\n\r\nPerhaps instead we should just change the `parse` middleware to `throw` if `response.bodyUsed` is true? That would hopefully prevent people from parsing twice in dev."}}
{"actor":{"display_login":"mjackson"}}