{"action":"created","issue":{"url":"https://api.github.com/repos/Huachao/vscode-restclient/issues/164","repository_url":"https://api.github.com/repos/Huachao/vscode-restclient","labels_url":"https://api.github.com/repos/Huachao/vscode-restclient/issues/164/labels{/name}","comments_url":"https://api.github.com/repos/Huachao/vscode-restclient/issues/164/comments","events_url":"https://api.github.com/repos/Huachao/vscode-restclient/issues/164/events","html_url":"https://github.com/Huachao/vscode-restclient/pull/164","id":296167852,"node_id":"MDExOlB1bGxSZXF1ZXN0MTY4NDQwMzQ1","number":164,"title":"Request scripts","user":{"login":"mkloubert","id":4951215,"node_id":"MDQ6VXNlcjQ5NTEyMTU=","avatar_url":"https://avatars2.githubusercontent.com/u/4951215?v=4","gravatar_id":"","url":"https://api.github.com/users/mkloubert","html_url":"https://github.com/mkloubert","followers_url":"https://api.github.com/users/mkloubert/followers","following_url":"https://api.github.com/users/mkloubert/following{/other_user}","gists_url":"https://api.github.com/users/mkloubert/gists{/gist_id}","starred_url":"https://api.github.com/users/mkloubert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkloubert/subscriptions","organizations_url":"https://api.github.com/users/mkloubert/orgs","repos_url":"https://api.github.com/users/mkloubert/repos","events_url":"https://api.github.com/users/mkloubert/events{/privacy}","received_events_url":"https://api.github.com/users/mkloubert/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-02-11T07:11:46Z","updated_at":"2018-10-15T17:48:29Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/Huachao/vscode-restclient/pulls/164","html_url":"https://github.com/Huachao/vscode-restclient/pull/164","diff_url":"https://github.com/Huachao/vscode-restclient/pull/164.diff","patch_url":"https://github.com/Huachao/vscode-restclient/pull/164.patch"},"body":"![scripts](https://user-images.githubusercontent.com/4951215/36070788-bbe70a2a-0f02-11e8-9fd6-0674b6a24d7c.gif)\r\n\r\nI have implemented a new feature, which is able to run JavaScript code for a `.http` or `.rest` file (s.\r\n [request_scripts](https://github.com/mkloubert/vscode-restclient/tree/request_scripts) branch).\r\n\r\nThis makes it possible to realize batch operations, e.g.\r\n\r\n**Example:**\r\n\r\nYou have a list of user IDs in a file like `users.txt`:\r\n\r\n```\r\n1\r\n2\r\n3\r\n```\r\n\r\nAnd a request like that:\r\n\r\n```http\r\nPOST https://example.com/users/{{uid}}\r\n\r\n{{body}}\r\n```\r\n\r\nYou can run a JavaScript for each of that values:\r\n\r\n```javascript\r\n// load the list of user IDs\r\nconst USER_IDS = $fs.readFileSync($cwd + '/users.txt', 'utf8')\r\n                    .split(\"\\n\")\r\n                    .map(line => line.trim())\r\n                    .filter(line => '' !== line);\r\n\r\n$each(USER_IDS, (userId) => {\r\n    // update progress text\r\n    $progress(\"Loading data of user '\" + userId + \"' ...\");\r\n\r\n    // run a request for 'userId'\r\n    return $request(\r\n        // vars\r\n        {\r\n            // @uid\r\n            'uid': userId,            \r\n            // @body\r\n            'body': $fs.readFileSync($cwd + '/user_to_create_' + userId + '.json')\r\n        },\r\n\r\n        // completed action\r\n        (err, response) => {\r\n            if (err) {\r\n                $vscode.window.showErrorMessage('ERROR: ' + err);\r\n            }\r\n            else {\r\n                $fs.writeFileSync($cwd + '/new_user_' + userId + '.json',\r\n                                  response.body,\r\n                                  'ascii');\r\n            }\r\n        }\r\n    );\r\n});\r\n```\r\n\r\nIf you select `Run As REST Script` in the context menu from the editor of the script, the user is asked for the `.http` or `.rest` file, the script should be run for.\r\n\r\nFor more information see [current README](https://github.com/mkloubert/vscode-restclient/tree/request_scripts#scripts) file."},"comment":{"url":"https://api.github.com/repos/Huachao/vscode-restclient/issues/comments/429949213","html_url":"https://github.com/Huachao/vscode-restclient/pull/164#issuecomment-429949213","issue_url":"https://api.github.com/repos/Huachao/vscode-restclient/issues/164","id":429949213,"node_id":"MDEyOklzc3VlQ29tbWVudDQyOTk0OTIxMw==","user":{"login":"ginomessmer","id":8465892,"node_id":"MDQ6VXNlcjg0NjU4OTI=","avatar_url":"https://avatars1.githubusercontent.com/u/8465892?v=4","gravatar_id":"","url":"https://api.github.com/users/ginomessmer","html_url":"https://github.com/ginomessmer","followers_url":"https://api.github.com/users/ginomessmer/followers","following_url":"https://api.github.com/users/ginomessmer/following{/other_user}","gists_url":"https://api.github.com/users/ginomessmer/gists{/gist_id}","starred_url":"https://api.github.com/users/ginomessmer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ginomessmer/subscriptions","organizations_url":"https://api.github.com/users/ginomessmer/orgs","repos_url":"https://api.github.com/users/ginomessmer/repos","events_url":"https://api.github.com/users/ginomessmer/events{/privacy}","received_events_url":"https://api.github.com/users/ginomessmer/received_events","type":"User","site_admin":false},"created_at":"2018-10-15T17:48:29Z","updated_at":"2018-10-15T17:48:29Z","author_association":"NONE","body":"+1 would love to see this feature."}}
{"actor":{"display_login":"ginomessmer"}}