{"action":"created","comment":{"url":"https://api.github.com/repos/mcollina/fastify/pulls/comments/93750232","pull_request_review_id":14284408,"id":93750232,"diff_hunk":"@@ -173,11 +191,47 @@ An object including the following properties:\n <a name=\"reply\"></a>\n #### Reply\n \n-A function that accepts the following parameters:\n+An object that exposes three APIs.\n+* `.send(payload)` - Sends the payload to the user, could be a plain text, JSON, stream, or an Error object.\n+* `.code(statusCode)` - Sets the status code (default to 200).\n+* `.header(name, value)` - Sets the headers.\n \n-* `error` - error object *(mandatory)*\n-* `statusCode` - the http status code *(optional, default to 200)*\n-* `object` - JavaScript object that will be JSONified *(mandatory)*\n+Example:\n+```js\n+fastify.get('/', schema, function (request, reply) {\n+  reply\n+    .code(200)\n+    .header('Content-Type', 'application/json')\n+    .send({ hello 'world' })\n+})\n+```\n+\n+Reply.send() accepts also Promises:\n+```js\n+fastify.get('/', schema, function (request, reply) {\n+  const promise = new Promise(function (resolve, reject) {\n+    if (condition) {\n+      resolve({ hello: 'world' })\n+    } else {\n+      reject(new Error('some error'))\n+    }\n+  })\n+\n+  reply\n+    .code(200)\n+    .header('Content-Type', 'application/json')\n+    .send(promise)\n+})\n+```\n+\n+To send a stream, just pass it as a parameter to .send(), the default `Content-Type` for the streams is `application/octet-stream`. [Pump](https://github.com/mafintosh/pump) is used to pipe the streams.\n+```js\n+fastify.get('/', schema, function (request, reply) {\n+  const fs = require('fs')\n+  const stream = fs.createReadStream('some-file', 'utf8')  \n+  reply.send(stream)\n+})\n+```","path":"README.md","position":139,"original_position":139,"commit_id":"a7c3ae962e12788f8d8a78a3a22072e380639f75","original_commit_id":"a7c3ae962e12788f8d8a78a3a22072e380639f75","user":{"login":"mcollina","id":52195,"avatar_url":"https://avatars.githubusercontent.com/u/52195?v=3","gravatar_id":"","url":"https://api.github.com/users/mcollina","html_url":"https://github.com/mcollina","followers_url":"https://api.github.com/users/mcollina/followers","following_url":"https://api.github.com/users/mcollina/following{/other_user}","gists_url":"https://api.github.com/users/mcollina/gists{/gist_id}","starred_url":"https://api.github.com/users/mcollina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcollina/subscriptions","organizations_url":"https://api.github.com/users/mcollina/orgs","repos_url":"https://api.github.com/users/mcollina/repos","events_url":"https://api.github.com/users/mcollina/events{/privacy}","received_events_url":"https://api.github.com/users/mcollina/received_events","type":"User","site_admin":false},"body":"can I override the `'Content-Type'`?","created_at":"2016-12-23T10:28:41Z","updated_at":"2016-12-23T10:28:41Z","html_url":"https://github.com/mcollina/fastify/pull/27#discussion_r93750232","pull_request_url":"https://api.github.com/repos/mcollina/fastify/pulls/27","_links":{"self":{"href":"https://api.github.com/repos/mcollina/fastify/pulls/comments/93750232"},"html":{"href":"https://github.com/mcollina/fastify/pull/27#discussion_r93750232"},"pull_request":{"href":"https://api.github.com/repos/mcollina/fastify/pulls/27"}}},"pull_request":{"url":"https://api.github.com/repos/mcollina/fastify/pulls/27","id":96890409,"html_url":"https://github.com/mcollina/fastify/pull/27","diff_url":"https://github.com/mcollina/fastify/pull/27.diff","patch_url":"https://github.com/mcollina/fastify/pull/27.patch","issue_url":"https://api.github.com/repos/mcollina/fastify/issues/27","number":27,"state":"open","locked":false,"title":"Reply refactor","user":{"login":"delvedor","id":4865608,"avatar_url":"https://avatars.githubusercontent.com/u/4865608?v=3","gravatar_id":"","url":"https://api.github.com/users/delvedor","html_url":"https://github.com/delvedor","followers_url":"https://api.github.com/users/delvedor/followers","following_url":"https://api.github.com/users/delvedor/following{/other_user}","gists_url":"https://api.github.com/users/delvedor/gists{/gist_id}","starred_url":"https://api.github.com/users/delvedor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/delvedor/subscriptions","organizations_url":"https://api.github.com/users/delvedor/orgs","repos_url":"https://api.github.com/users/delvedor/repos","events_url":"https://api.github.com/users/delvedor/events{/privacy}","received_events_url":"https://api.github.com/users/delvedor/received_events","type":"User","site_admin":false},"body":"At the moment in master we can serve around 17k req / sec, with this change we can serve around 19.5k req / sec.\r\nIs a ~15% improvement, that's good!\r\n\r\nBut this perf improvement implies an awful API, `reply.reply`.\r\nExample:\r\n```js\r\nfastify\r\n   .get('/', schema, function (req, reply) {\r\n     reply.header('Content-Type', 'application-json').code(200)\r\n     reply.reply(null, {hello: 'world'})\r\n   })\r\n```\r\n@mcollina @davidmarkclements do you know any ninja trick to get this perf but have a nice looking API?\r\n\r\nps for the moment I disabled all the test, since all of them will fail.\r\n__________\r\n\r\n**TODO**:\r\nStream:\r\n- [x] Test\r\n- [x] Docs\r\n- [ ] What to do if pump fails\r\n\r\nReply:\r\n- [x] Promises support\r\n- [x] Test\r\n- [x] Docs\r\n- [ ] Async/Await support\r\n","created_at":"2016-12-07T09:53:40Z","updated_at":"2016-12-23T10:28:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cd84db2381ed80a2ee5058687cd43d30ae22a0ae","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/mcollina/fastify/pulls/27/commits","review_comments_url":"https://api.github.com/repos/mcollina/fastify/pulls/27/comments","review_comment_url":"https://api.github.com/repos/mcollina/fastify/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mcollina/fastify/issues/27/comments","statuses_url":"https://api.github.com/repos/mcollina/fastify/statuses/a7c3ae962e12788f8d8a78a3a22072e380639f75","head":{"label":"mcollina:reply-refactor","ref":"reply-refactor","sha":"a7c3ae962e12788f8d8a78a3a22072e380639f75","user":{"login":"mcollina","id":52195,"avatar_url":"https://avatars.githubusercontent.com/u/52195?v=3","gravatar_id":"","url":"https://api.github.com/users/mcollina","html_url":"https://github.com/mcollina","followers_url":"https://api.github.com/users/mcollina/followers","following_url":"https://api.github.com/users/mcollina/following{/other_user}","gists_url":"https://api.github.com/users/mcollina/gists{/gist_id}","starred_url":"https://api.github.com/users/mcollina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcollina/subscriptions","organizations_url":"https://api.github.com/users/mcollina/orgs","repos_url":"https://api.github.com/users/mcollina/repos","events_url":"https://api.github.com/users/mcollina/events{/privacy}","received_events_url":"https://api.github.com/users/mcollina/received_events","type":"User","site_admin":false},"repo":{"id":69495170,"name":"fastify","full_name":"mcollina/fastify","owner":{"login":"mcollina","id":52195,"avatar_url":"https://avatars.githubusercontent.com/u/52195?v=3","gravatar_id":"","url":"https://api.github.com/users/mcollina","html_url":"https://github.com/mcollina","followers_url":"https://api.github.com/users/mcollina/followers","following_url":"https://api.github.com/users/mcollina/following{/other_user}","gists_url":"https://api.github.com/users/mcollina/gists{/gist_id}","starred_url":"https://api.github.com/users/mcollina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcollina/subscriptions","organizations_url":"https://api.github.com/users/mcollina/orgs","repos_url":"https://api.github.com/users/mcollina/repos","events_url":"https://api.github.com/users/mcollina/events{/privacy}","received_events_url":"https://api.github.com/users/mcollina/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mcollina/fastify","description":"Fast and low overhead web framework, for Node.js","fork":false,"url":"https://api.github.com/repos/mcollina/fastify","forks_url":"https://api.github.com/repos/mcollina/fastify/forks","keys_url":"https://api.github.com/repos/mcollina/fastify/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mcollina/fastify/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mcollina/fastify/teams","hooks_url":"https://api.github.com/repos/mcollina/fastify/hooks","issue_events_url":"https://api.github.com/repos/mcollina/fastify/issues/events{/number}","events_url":"https://api.github.com/repos/mcollina/fastify/events","assignees_url":"https://api.github.com/repos/mcollina/fastify/assignees{/user}","branches_url":"https://api.github.com/repos/mcollina/fastify/branches{/branch}","tags_url":"https://api.github.com/repos/mcollina/fastify/tags","blobs_url":"https://api.github.com/repos/mcollina/fastify/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mcollina/fastify/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mcollina/fastify/git/refs{/sha}","trees_url":"https://api.github.com/repos/mcollina/fastify/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mcollina/fastify/statuses/{sha}","languages_url":"https://api.github.com/repos/mcollina/fastify/languages","stargazers_url":"https://api.github.com/repos/mcollina/fastify/stargazers","contributors_url":"https://api.github.com/repos/mcollina/fastify/contributors","subscribers_url":"https://api.github.com/repos/mcollina/fastify/subscribers","subscription_url":"https://api.github.com/repos/mcollina/fastify/subscription","commits_url":"https://api.github.com/repos/mcollina/fastify/commits{/sha}","git_commits_url":"https://api.github.com/repos/mcollina/fastify/git/commits{/sha}","comments_url":"https://api.github.com/repos/mcollina/fastify/comments{/number}","issue_comment_url":"https://api.github.com/repos/mcollina/fastify/issues/comments{/number}","contents_url":"https://api.github.com/repos/mcollina/fastify/contents/{+path}","compare_url":"https://api.github.com/repos/mcollina/fastify/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mcollina/fastify/merges","archive_url":"https://api.github.com/repos/mcollina/fastify/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mcollina/fastify/downloads","issues_url":"https://api.github.com/repos/mcollina/fastify/issues{/number}","pulls_url":"https://api.github.com/repos/mcollina/fastify/pulls{/number}","milestones_url":"https://api.github.com/repos/mcollina/fastify/milestones{/number}","notifications_url":"https://api.github.com/repos/mcollina/fastify/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mcollina/fastify/labels{/name}","releases_url":"https://api.github.com/repos/mcollina/fastify/releases{/id}","deployments_url":"https://api.github.com/repos/mcollina/fastify/deployments","created_at":"2016-09-28T19:10:14Z","updated_at":"2016-12-20T01:51:34Z","pushed_at":"2016-12-23T10:19:47Z","git_url":"git://github.com/mcollina/fastify.git","ssh_url":"git@github.com:mcollina/fastify.git","clone_url":"https://github.com/mcollina/fastify.git","svn_url":"https://github.com/mcollina/fastify","homepage":"","size":81,"stargazers_count":49,"watchers_count":49,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":8,"forks":3,"open_issues":8,"watchers":49,"default_branch":"master"}},"base":{"label":"mcollina:master","ref":"master","sha":"1e4f3a013ada54ed85e321deffef358799836925","user":{"login":"mcollina","id":52195,"avatar_url":"https://avatars.githubusercontent.com/u/52195?v=3","gravatar_id":"","url":"https://api.github.com/users/mcollina","html_url":"https://github.com/mcollina","followers_url":"https://api.github.com/users/mcollina/followers","following_url":"https://api.github.com/users/mcollina/following{/other_user}","gists_url":"https://api.github.com/users/mcollina/gists{/gist_id}","starred_url":"https://api.github.com/users/mcollina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcollina/subscriptions","organizations_url":"https://api.github.com/users/mcollina/orgs","repos_url":"https://api.github.com/users/mcollina/repos","events_url":"https://api.github.com/users/mcollina/events{/privacy}","received_events_url":"https://api.github.com/users/mcollina/received_events","type":"User","site_admin":false},"repo":{"id":69495170,"name":"fastify","full_name":"mcollina/fastify","owner":{"login":"mcollina","id":52195,"avatar_url":"https://avatars.githubusercontent.com/u/52195?v=3","gravatar_id":"","url":"https://api.github.com/users/mcollina","html_url":"https://github.com/mcollina","followers_url":"https://api.github.com/users/mcollina/followers","following_url":"https://api.github.com/users/mcollina/following{/other_user}","gists_url":"https://api.github.com/users/mcollina/gists{/gist_id}","starred_url":"https://api.github.com/users/mcollina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcollina/subscriptions","organizations_url":"https://api.github.com/users/mcollina/orgs","repos_url":"https://api.github.com/users/mcollina/repos","events_url":"https://api.github.com/users/mcollina/events{/privacy}","received_events_url":"https://api.github.com/users/mcollina/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mcollina/fastify","description":"Fast and low overhead web framework, for Node.js","fork":false,"url":"https://api.github.com/repos/mcollina/fastify","forks_url":"https://api.github.com/repos/mcollina/fastify/forks","keys_url":"https://api.github.com/repos/mcollina/fastify/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mcollina/fastify/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mcollina/fastify/teams","hooks_url":"https://api.github.com/repos/mcollina/fastify/hooks","issue_events_url":"https://api.github.com/repos/mcollina/fastify/issues/events{/number}","events_url":"https://api.github.com/repos/mcollina/fastify/events","assignees_url":"https://api.github.com/repos/mcollina/fastify/assignees{/user}","branches_url":"https://api.github.com/repos/mcollina/fastify/branches{/branch}","tags_url":"https://api.github.com/repos/mcollina/fastify/tags","blobs_url":"https://api.github.com/repos/mcollina/fastify/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mcollina/fastify/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mcollina/fastify/git/refs{/sha}","trees_url":"https://api.github.com/repos/mcollina/fastify/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mcollina/fastify/statuses/{sha}","languages_url":"https://api.github.com/repos/mcollina/fastify/languages","stargazers_url":"https://api.github.com/repos/mcollina/fastify/stargazers","contributors_url":"https://api.github.com/repos/mcollina/fastify/contributors","subscribers_url":"https://api.github.com/repos/mcollina/fastify/subscribers","subscription_url":"https://api.github.com/repos/mcollina/fastify/subscription","commits_url":"https://api.github.com/repos/mcollina/fastify/commits{/sha}","git_commits_url":"https://api.github.com/repos/mcollina/fastify/git/commits{/sha}","comments_url":"https://api.github.com/repos/mcollina/fastify/comments{/number}","issue_comment_url":"https://api.github.com/repos/mcollina/fastify/issues/comments{/number}","contents_url":"https://api.github.com/repos/mcollina/fastify/contents/{+path}","compare_url":"https://api.github.com/repos/mcollina/fastify/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mcollina/fastify/merges","archive_url":"https://api.github.com/repos/mcollina/fastify/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mcollina/fastify/downloads","issues_url":"https://api.github.com/repos/mcollina/fastify/issues{/number}","pulls_url":"https://api.github.com/repos/mcollina/fastify/pulls{/number}","milestones_url":"https://api.github.com/repos/mcollina/fastify/milestones{/number}","notifications_url":"https://api.github.com/repos/mcollina/fastify/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mcollina/fastify/labels{/name}","releases_url":"https://api.github.com/repos/mcollina/fastify/releases{/id}","deployments_url":"https://api.github.com/repos/mcollina/fastify/deployments","created_at":"2016-09-28T19:10:14Z","updated_at":"2016-12-20T01:51:34Z","pushed_at":"2016-12-23T10:19:47Z","git_url":"git://github.com/mcollina/fastify.git","ssh_url":"git@github.com:mcollina/fastify.git","clone_url":"https://github.com/mcollina/fastify.git","svn_url":"https://github.com/mcollina/fastify","homepage":"","size":81,"stargazers_count":49,"watchers_count":49,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":8,"forks":3,"open_issues":8,"watchers":49,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mcollina/fastify/pulls/27"},"html":{"href":"https://github.com/mcollina/fastify/pull/27"},"issue":{"href":"https://api.github.com/repos/mcollina/fastify/issues/27"},"comments":{"href":"https://api.github.com/repos/mcollina/fastify/issues/27/comments"},"review_comments":{"href":"https://api.github.com/repos/mcollina/fastify/pulls/27/comments"},"review_comment":{"href":"https://api.github.com/repos/mcollina/fastify/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mcollina/fastify/pulls/27/commits"},"statuses":{"href":"https://api.github.com/repos/mcollina/fastify/statuses/a7c3ae962e12788f8d8a78a3a22072e380639f75"}}}}
{"actor":{"display_login":"mcollina"}}