{"action":"created","comment":{"url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/pulls/comments/26453372","id":26453372,"diff_hunk":"@@ -13,68 +13,125 @@ npm install\n \n ## Usage\n \n-Start the REPL from the terminal:\n+#### Start the interactive shell\n ```bash\n node run\n ```\n The command prompt `KnowSheet> ` will appear.\n \n-... or evaluate one expression from the command-line:\n+#### Evaluate from the command-line\n ```bash\n echo 'HTTP(GET(\"http://httpbin.org/get?query=1\")).body' | node run\n ```\n+If `stdin` is not a `tty`, the shell starts in a non-interactive mode.\n \n-... or evaluate and pass the result to another command:\n+#### Evaluate and pass the result to another command\n ```bash\n echo 'HTTP(GET(\"http://httpbin.org/get?query=1\")).body' | node run | cat\n ```\n+If `stdout` is not a `tty`, the result is emitted as text into `stdout`, the errors are emitted as text into `stderr`.\n \n-Override the default prompt:\n+#### Override the default prompt\n ```bash\n node run --prompt 'Bricks> '\n ```\n The command prompt `Bricks> ` will appear.\n \n-### Expressions\n+### HTTP client\n \n-Perform an HTTP GET request and print the response:\n+* Bricks provides utilities to perform HTTP requests.\n+* By default, the redirects are forbidden and result in an error. They can be enabled per request.\n+\n+#### Perform an HTTP GET request\n ```\n KnowSheet> HTTP(GET(\"http://httpbin.org/get?query=1\")).body\n ```\n \n-Perform an HTTP POST request and print the response:\n+#### Perform an HTTP POST request\n ```\n KnowSheet> HTTP(POST(\"http://httpbin.org/post\", \"BODY\", \"text/plain\")).body\n ```\n \n-Parse a JSON response into an object, get a field from it:\n+#### Allow redirects\n ```\n-KnowSheet> JSONParse(HTTP(GET(\"http://httpbin.org/get?query=1\")).body).args\n+KnowSheet> HTTP(GET(\"http://httpbin.org/redirect/5\").AllowRedirects()).body\n ```\n \n-POST a JSON-encoded object:\n+#### Provide a custom `User-Agent`\n ```\n-KnowSheet> JSONParse(HTTP(POST(\"http://httpbin.org/post\", DemoObject())).body).json\n+KnowSheet> HTTP(GET(\"http://httpbin.org/get\").UserAgent(\"KnowSheet-REPL/1.0.0\")).body\n ```\n-<sup>The syntax mimics C++ Bricks exactly, as long as `DemoObject` is defined as a serializable type.</sup>\n \n-Allow redirects:\n+#### Provide extra HTTP headers\n+For `GET` requests:\n ```\n-KnowSheet> HTTP(GET(\"http://httpbin.org/redirect/5\").AllowRedirects()).body\n+KnowSheet> HTTP(GET(\"http://httpbin.org/get?query=1\", HTTPHeaders().Set(\"Custom\", \"Header\"))).body\n ```\n \n-Provide a custom User-Agent:\n+For `POST` requests:\n ```\n-KnowSheet> HTTP(GET(\"http://httpbin.org/get\").UserAgent(\"KnowSheet-REPL/1.0.0\")).body\n+KnowSheet> HTTP(POST(\"http://httpbin.org/post\", \"BODY\", \"text/plain\", HTTPHeaders().Set(\"Custom\", \"Header\"))).body\n ```\n \n-Provide extra HTTP headers:\n+### HTTP server\n+\n+* Bricks maintains a single server per port.\n+* Each server accepts connections since start till the process exits.\n+* There can only be a single handler for a given path.\n+* The calls to the server methods can be chained.\n+* The handler lambda syntax in the REPL mimics C++11 to a certain extent -- no full lambda support guaranteed.\n+\n+#### Start an HTTP server\n ```\n-KnowSheet> HTTP(GET(\"http://httpbin.org/get?query=1\", HTTPHeaders().Set(\"Custom\", \"Header\"))).body\n-KnowSheet> HTTP(POST(\"http://httpbin.org/post\", \"BODY\", \"text/plain\", HTTPHeaders().Set(\"Custom\", \"Header\"))).body\n+KnowSheet> HTTP(2015)","path":"README.md","position":100,"original_position":100,"commit_id":"e1ab37056a1b0e444394a1809e32ad33abd78dc5","original_commit_id":"ebfb9f61d1a1c2c016be05b412b51606ab1b092e","user":{"login":"sompylasar","id":498274,"avatar_url":"https://avatars.githubusercontent.com/u/498274?v=3","gravatar_id":"","url":"https://api.github.com/users/sompylasar","html_url":"https://github.com/sompylasar","followers_url":"https://api.github.com/users/sompylasar/followers","following_url":"https://api.github.com/users/sompylasar/following{/other_user}","gists_url":"https://api.github.com/users/sompylasar/gists{/gist_id}","starred_url":"https://api.github.com/users/sompylasar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sompylasar/subscriptions","organizations_url":"https://api.github.com/users/sompylasar/orgs","repos_url":"https://api.github.com/users/sompylasar/repos","events_url":"https://api.github.com/users/sompylasar/events{/privacy}","received_events_url":"https://api.github.com/users/sompylasar/received_events","type":"User","site_admin":false},"body":"Fixed in https://github.com/sompylasar/KnowSheet-REPL/commit/ec85e8110745a7fdeae64bde810ea64033bf3589","created_at":"2015-03-15T22:40:46Z","updated_at":"2015-03-15T22:40:46Z","html_url":"https://github.com/KnowSheet/KnowSheet-REPL/pull/8#discussion_r26453372","pull_request_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/pulls/8","_links":{"self":{"href":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/pulls/comments/26453372"},"html":{"href":"https://github.com/KnowSheet/KnowSheet-REPL/pull/8#discussion_r26453372"},"pull_request":{"href":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/pulls/8"}}},"pull_request":{"url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/pulls/8","id":30818426,"html_url":"https://github.com/KnowSheet/KnowSheet-REPL/pull/8","diff_url":"https://github.com/KnowSheet/KnowSheet-REPL/pull/8.diff","patch_url":"https://github.com/KnowSheet/KnowSheet-REPL/pull/8.patch","issue_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/issues/8","number":8,"state":"closed","locked":false,"title":"REPL HTTP server","user":{"login":"sompylasar","id":498274,"avatar_url":"https://avatars.githubusercontent.com/u/498274?v=3","gravatar_id":"","url":"https://api.github.com/users/sompylasar","html_url":"https://github.com/sompylasar","followers_url":"https://api.github.com/users/sompylasar/followers","following_url":"https://api.github.com/users/sompylasar/following{/other_user}","gists_url":"https://api.github.com/users/sompylasar/gists{/gist_id}","starred_url":"https://api.github.com/users/sompylasar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sompylasar/subscriptions","organizations_url":"https://api.github.com/users/sompylasar/orgs","repos_url":"https://api.github.com/users/sompylasar/repos","events_url":"https://api.github.com/users/sompylasar/events{/privacy}","received_events_url":"https://api.github.com/users/sompylasar/received_events","type":"User","site_admin":false},"body":"Example: `echo 'HTTP(2014).Register(\"/test\", [](Request r) { r(\"OK\");\n}); HTTP(GET(\"localhost:2014/test\")).body' | node run`","created_at":"2015-03-10T02:41:27Z","updated_at":"2015-03-15T22:40:46Z","closed_at":"2015-03-13T14:42:05Z","merged_at":"2015-03-13T14:42:05Z","merge_commit_sha":"07642311ce6ad52bb5463554130e968d7d160546","assignee":{"login":"dkorolev","id":2159447,"avatar_url":"https://avatars.githubusercontent.com/u/2159447?v=3","gravatar_id":"","url":"https://api.github.com/users/dkorolev","html_url":"https://github.com/dkorolev","followers_url":"https://api.github.com/users/dkorolev/followers","following_url":"https://api.github.com/users/dkorolev/following{/other_user}","gists_url":"https://api.github.com/users/dkorolev/gists{/gist_id}","starred_url":"https://api.github.com/users/dkorolev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkorolev/subscriptions","organizations_url":"https://api.github.com/users/dkorolev/orgs","repos_url":"https://api.github.com/users/dkorolev/repos","events_url":"https://api.github.com/users/dkorolev/events{/privacy}","received_events_url":"https://api.github.com/users/dkorolev/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/pulls/8/commits","review_comments_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/pulls/8/comments","review_comment_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/pulls/comments{/number}","comments_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/issues/8/comments","statuses_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/statuses/e1ab37056a1b0e444394a1809e32ad33abd78dc5","head":{"label":"sompylasar:repl-http-server","ref":"repl-http-server","sha":"e1ab37056a1b0e444394a1809e32ad33abd78dc5","user":{"login":"sompylasar","id":498274,"avatar_url":"https://avatars.githubusercontent.com/u/498274?v=3","gravatar_id":"","url":"https://api.github.com/users/sompylasar","html_url":"https://github.com/sompylasar","followers_url":"https://api.github.com/users/sompylasar/followers","following_url":"https://api.github.com/users/sompylasar/following{/other_user}","gists_url":"https://api.github.com/users/sompylasar/gists{/gist_id}","starred_url":"https://api.github.com/users/sompylasar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sompylasar/subscriptions","organizations_url":"https://api.github.com/users/sompylasar/orgs","repos_url":"https://api.github.com/users/sompylasar/repos","events_url":"https://api.github.com/users/sompylasar/events{/privacy}","received_events_url":"https://api.github.com/users/sompylasar/received_events","type":"User","site_admin":false},"repo":{"id":31201354,"name":"KnowSheet-REPL","full_name":"sompylasar/KnowSheet-REPL","owner":{"login":"sompylasar","id":498274,"avatar_url":"https://avatars.githubusercontent.com/u/498274?v=3","gravatar_id":"","url":"https://api.github.com/users/sompylasar","html_url":"https://github.com/sompylasar","followers_url":"https://api.github.com/users/sompylasar/followers","following_url":"https://api.github.com/users/sompylasar/following{/other_user}","gists_url":"https://api.github.com/users/sompylasar/gists{/gist_id}","starred_url":"https://api.github.com/users/sompylasar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sompylasar/subscriptions","organizations_url":"https://api.github.com/users/sompylasar/orgs","repos_url":"https://api.github.com/users/sompylasar/repos","events_url":"https://api.github.com/users/sompylasar/events{/privacy}","received_events_url":"https://api.github.com/users/sompylasar/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sompylasar/KnowSheet-REPL","description":"REPL interactive shell for Bricks.","fork":true,"url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL","forks_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/forks","keys_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/teams","hooks_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/hooks","issue_events_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/issues/events{/number}","events_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/events","assignees_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/assignees{/user}","branches_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/branches{/branch}","tags_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/tags","blobs_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/git/refs{/sha}","trees_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/statuses/{sha}","languages_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/languages","stargazers_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/stargazers","contributors_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/contributors","subscribers_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/subscribers","subscription_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/subscription","commits_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/commits{/sha}","git_commits_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/git/commits{/sha}","comments_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/comments{/number}","issue_comment_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/issues/comments{/number}","contents_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/contents/{+path}","compare_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/merges","archive_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/downloads","issues_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/issues{/number}","pulls_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/pulls{/number}","milestones_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/milestones{/number}","notifications_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/labels{/name}","releases_url":"https://api.github.com/repos/sompylasar/KnowSheet-REPL/releases{/id}","created_at":"2015-02-23T09:32:24Z","updated_at":"2015-03-15T22:25:34Z","pushed_at":"2015-03-15T22:40:24Z","git_url":"git://github.com/sompylasar/KnowSheet-REPL.git","ssh_url":"git@github.com:sompylasar/KnowSheet-REPL.git","clone_url":"https://github.com/sompylasar/KnowSheet-REPL.git","svn_url":"https://github.com/sompylasar/KnowSheet-REPL","homepage":null,"size":284,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"KnowSheet:master","ref":"master","sha":"e0dbe1bea604b342d94dc4584f48933dddc2438d","user":{"login":"KnowSheet","id":9897562,"avatar_url":"https://avatars.githubusercontent.com/u/9897562?v=3","gravatar_id":"","url":"https://api.github.com/users/KnowSheet","html_url":"https://github.com/KnowSheet","followers_url":"https://api.github.com/users/KnowSheet/followers","following_url":"https://api.github.com/users/KnowSheet/following{/other_user}","gists_url":"https://api.github.com/users/KnowSheet/gists{/gist_id}","starred_url":"https://api.github.com/users/KnowSheet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KnowSheet/subscriptions","organizations_url":"https://api.github.com/users/KnowSheet/orgs","repos_url":"https://api.github.com/users/KnowSheet/repos","events_url":"https://api.github.com/users/KnowSheet/events{/privacy}","received_events_url":"https://api.github.com/users/KnowSheet/received_events","type":"Organization","site_admin":false},"repo":{"id":31192019,"name":"KnowSheet-REPL","full_name":"KnowSheet/KnowSheet-REPL","owner":{"login":"KnowSheet","id":9897562,"avatar_url":"https://avatars.githubusercontent.com/u/9897562?v=3","gravatar_id":"","url":"https://api.github.com/users/KnowSheet","html_url":"https://github.com/KnowSheet","followers_url":"https://api.github.com/users/KnowSheet/followers","following_url":"https://api.github.com/users/KnowSheet/following{/other_user}","gists_url":"https://api.github.com/users/KnowSheet/gists{/gist_id}","starred_url":"https://api.github.com/users/KnowSheet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KnowSheet/subscriptions","organizations_url":"https://api.github.com/users/KnowSheet/orgs","repos_url":"https://api.github.com/users/KnowSheet/repos","events_url":"https://api.github.com/users/KnowSheet/events{/privacy}","received_events_url":"https://api.github.com/users/KnowSheet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/KnowSheet/KnowSheet-REPL","description":"A Read-Eval-Print-Loop (REPL) shell to demonstrate the KnowSheet Bricks C++ syntax.","fork":false,"url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL","forks_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/forks","keys_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/keys{/key_id}","collaborators_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/teams","hooks_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/hooks","issue_events_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/issues/events{/number}","events_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/events","assignees_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/assignees{/user}","branches_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/branches{/branch}","tags_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/tags","blobs_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/git/refs{/sha}","trees_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/git/trees{/sha}","statuses_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/statuses/{sha}","languages_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/languages","stargazers_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/stargazers","contributors_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/contributors","subscribers_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/subscribers","subscription_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/subscription","commits_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/commits{/sha}","git_commits_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/git/commits{/sha}","comments_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/comments{/number}","issue_comment_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/issues/comments{/number}","contents_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/contents/{+path}","compare_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/compare/{base}...{head}","merges_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/merges","archive_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/downloads","issues_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/issues{/number}","pulls_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/pulls{/number}","milestones_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/milestones{/number}","notifications_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/labels{/name}","releases_url":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/releases{/id}","created_at":"2015-02-23T03:05:25Z","updated_at":"2015-03-15T22:23:21Z","pushed_at":"2015-03-15T22:23:20Z","git_url":"git://github.com/KnowSheet/KnowSheet-REPL.git","ssh_url":"git@github.com:KnowSheet/KnowSheet-REPL.git","clone_url":"https://github.com/KnowSheet/KnowSheet-REPL.git","svn_url":"https://github.com/KnowSheet/KnowSheet-REPL","homepage":"","size":625,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/pulls/8"},"html":{"href":"https://github.com/KnowSheet/KnowSheet-REPL/pull/8"},"issue":{"href":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/issues/8"},"comments":{"href":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/issues/8/comments"},"review_comments":{"href":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/pulls/8/comments"},"review_comment":{"href":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/pulls/8/commits"},"statuses":{"href":"https://api.github.com/repos/KnowSheet/KnowSheet-REPL/statuses/e1ab37056a1b0e444394a1809e32ad33abd78dc5"}}}}