{"action":"created","issue":{"url":"https://api.github.com/repos/kemalcr/kemal/issues/248","repository_url":"https://api.github.com/repos/kemalcr/kemal","labels_url":"https://api.github.com/repos/kemalcr/kemal/issues/248/labels{/name}","comments_url":"https://api.github.com/repos/kemalcr/kemal/issues/248/comments","events_url":"https://api.github.com/repos/kemalcr/kemal/issues/248/events","html_url":"https://github.com/kemalcr/kemal/pull/248","id":188048246,"number":248,"title":"Add Halt Macros for JSON, HTML, and Plain Text Content-Types","user":{"login":"samueleaton","id":9119269,"avatar_url":"https://avatars.githubusercontent.com/u/9119269?v=3","gravatar_id":"","url":"https://api.github.com/users/samueleaton","html_url":"https://github.com/samueleaton","followers_url":"https://api.github.com/users/samueleaton/followers","following_url":"https://api.github.com/users/samueleaton/following{/other_user}","gists_url":"https://api.github.com/users/samueleaton/gists{/gist_id}","starred_url":"https://api.github.com/users/samueleaton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samueleaton/subscriptions","organizations_url":"https://api.github.com/users/samueleaton/orgs","repos_url":"https://api.github.com/users/samueleaton/repos","events_url":"https://api.github.com/users/samueleaton/events{/privacy}","received_events_url":"https://api.github.com/users/samueleaton/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-11-08T17:04:31Z","updated_at":"2016-12-19T01:19:27Z","closed_at":"2016-12-19T01:19:27Z","pull_request":{"url":"https://api.github.com/repos/kemalcr/kemal/pulls/248","html_url":"https://github.com/kemalcr/kemal/pull/248","diff_url":"https://github.com/kemalcr/kemal/pull/248.diff","patch_url":"https://github.com/kemalcr/kemal/pull/248.patch"},"body":"Adds `halt_json`, `halt_html`, `halt_plain` macros that do the same as `halt` but also set the Content-Type.\r\n\r\nInspired by Express, where you can easily respond with the content-type.\r\n\r\n**Express.js Example**\r\n\r\n```javascript\r\nrouter.get('/', (req, res) => {\r\n  const myArray = [{\"name\": \"sam\"}];\r\n  if (myArray.length < 1)\r\n    res.status(400).send('Empty array').end();\r\n  else\r\n    res.json(myArray).end();\r\n});\r\n```\r\n\r\n**Kemal Example**\r\n\r\nNow, in kemal, instead of doing this:\r\n\r\n```ruby\r\nget \"/\" do |env|\r\n  if my_object.nil?\r\n    env.response.content_type = \"text/plain\"\r\n    halt env, 400, \"Nil object. Cannot parse\"\r\n  else\r\n    env.response.content_type = \"application/json\"\r\n    halt env, 200, my_object.to_json\r\n  end\r\nend\r\n```\r\n\r\nYou can do this:\r\n\r\n```ruby\r\nget \"/\" do |env|\r\n  if my_object.nil?\r\n    halt_plain env, 400, \"Nil object. Cannot parse\"\r\n  else\r\n    halt_json env, 200, my_object.to_json\r\n  end\r\nend\r\n```"},"comment":{"url":"https://api.github.com/repos/kemalcr/kemal/issues/comments/267862224","html_url":"https://github.com/kemalcr/kemal/pull/248#issuecomment-267862224","issue_url":"https://api.github.com/repos/kemalcr/kemal/issues/248","id":267862224,"user":{"login":"samueleaton","id":9119269,"avatar_url":"https://avatars.githubusercontent.com/u/9119269?v=3","gravatar_id":"","url":"https://api.github.com/users/samueleaton","html_url":"https://github.com/samueleaton","followers_url":"https://api.github.com/users/samueleaton/followers","following_url":"https://api.github.com/users/samueleaton/following{/other_user}","gists_url":"https://api.github.com/users/samueleaton/gists{/gist_id}","starred_url":"https://api.github.com/users/samueleaton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samueleaton/subscriptions","organizations_url":"https://api.github.com/users/samueleaton/orgs","repos_url":"https://api.github.com/users/samueleaton/repos","events_url":"https://api.github.com/users/samueleaton/events{/privacy}","received_events_url":"https://api.github.com/users/samueleaton/received_events","type":"User","site_admin":false},"created_at":"2016-12-19T01:19:27Z","updated_at":"2016-12-19T01:19:27Z","body":"I'll close this and just define these in my own projects."}}
{"actor":{"display_login":"samueleaton"}}