{"id":41051168,"url":"https://github.com/brunodavi/http-script","last_synced_at":"2026-01-22T11:27:32.712Z","repository":{"id":257186455,"uuid":"857562416","full_name":"brunodavi/http-script","owner":"brunodavi","description":"Tool to easily create http request scripts","archived":false,"fork":false,"pushed_at":"2024-11-10T07:28:55.000Z","size":106,"stargazers_count":1,"open_issues_count":6,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-10T08:20:44.389Z","etag":null,"topics":["nodejs","rest-api","script"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brunodavi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-15T01:30:04.000Z","updated_at":"2024-11-10T07:22:45.000Z","dependencies_parsed_at":"2024-11-10T08:19:28.150Z","dependency_job_id":"7fbe6690-a104-4312-8960-3afe345eeb97","html_url":"https://github.com/brunodavi/http-script","commit_stats":null,"previous_names":["brunodavi/http-scripts","brunodavi/http-script"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/brunodavi/http-script","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunodavi%2Fhttp-script","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunodavi%2Fhttp-script/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunodavi%2Fhttp-script/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunodavi%2Fhttp-script/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brunodavi","download_url":"https://codeload.github.com/brunodavi/http-script/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunodavi%2Fhttp-script/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28662054,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T01:17:37.254Z","status":"online","status_checked_at":"2026-01-22T02:00:07.137Z","response_time":144,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nodejs","rest-api","script"],"created_at":"2026-01-22T11:27:31.919Z","updated_at":"2026-01-22T11:27:32.705Z","avatar_url":"https://github.com/brunodavi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HTTP Script\n\n[![Test](https://github.com/brunodavi/http-script/actions/workflows/test.yml/badge.svg)](https://github.com/brunodavi/http-script/actions/workflows/test.yml)\n\nTool to easily create http request scripts\n\n## Overview\n\n`http-script` is a tool that simplifies the creation and execution of HTTP scripts. This documentation provides an overview of the main features of the tool, including practical instructions and examples.\n\n### Sample Script\n\n```\npost httpbin.org/post\n\nq=word\nUser-Agent: HTTP Script\n\n.body\n{\"name\":\"John\",\"age\":31}\n.\n\n.js\nthis.state.user = JSON.parse(this.body)\n.\n\n\u003c path/to/fileSend.docx\n```\n\n```js\n{\n  method: \"POST\",\n  url: 'https://httpbin.org/post',\n\n  queries: { q: 'word' },\n  headers: { 'User-Agent': 'HTTP Script' },\n  body: '{\"name\":\"John\",\"age\":31}',\n\n  fileToSend: 'path/to/fileSend.docx',\n  saveFile: null,\n\n  state: { name: 'John', age: 31 },\n\n  js: 'this.state.user = JSON.parse(this.body)',\n\n  runJs(response) {\n    if (this.js) eval(this.js);\n  }\n}\n```\n\n### Installation\n\nTo install `http-script`, you can use npm or include the script directly in your HTML:\n\n```sh\nnpm install github:brunodavi/http-script\n```\n\nor use cdn:\n\n```html\nhttps://cdn.jsdelivr.net/gh/brunodavi/http-script@v2.1.0/dist/httpScript.min.js\n```\n\n### How to Use\n\n```js\nimport fs from 'fs'\nimport httpScript from 'http-script'\n\nasync function httpRequest(options) {\n  const fileToSend = options.fileToSend\n    ? fs.readFileSync(options.fileToSend)\n    : undefined\n\n  const headers = options.headers || {}\n  const body = options.body || fileToSend\n\n  const queryParams = new URLSearchParams(options.queries).toString()\n  const url =\n    options.queries \u0026\u0026 queryParams\n      ? `${options.url}?${queryParams}`\n      : options.url\n\n  const response = await fetch(url, {\n    method: options.method,\n    headers: headers,\n    body: body,\n  })\n\n  if (options.saveFile) {\n    fs.writeFileSync(options.saveFile, await response.text())\n  }\n\n  return response\n}\n\nconst restScript = `\ng httpbin.org\n\n---\n\np /post\n`\n\nhttpScript.run(restScript, httpRequest).then(console.log)\n```\n\n### Script Structure\n\n#### Available Methods\n\nHTTP methods are defined on the first line of the script and can be abbreviated or written in full, in either uppercase or lowercase:\n\n- `g` or `get`\n- `p` or `post`\n- `u` or `put`\n- `a` or `patch`\n- `d` or `delete`\n- `h` or `head`\n- `o` or `options`\n- `t` or `trace`\n\n#### URL\n\nThe URL follows the method and can be written in various forms:\n\n- `httpbin.org` = `https://httpbin.org`\n- `localhost` = `http://localhost`\n- `:1234` = `http://localhost:1234`\n- `0.0.0.0` = `http://0.0.0.0`\n\n##### Example\n\n```\ng :1234 = # GET http://localhost:1234\n```\n\n#### Queries\n\nAdditional parameters for the request can be specified after the URL or on separate lines:\n\n##### Example\n\n```\nGet :1234/search\n\nq=item\npage=2\n```\n\nor\n\n```\nget :1234/search?q=item\u0026page=2\n```\n\n#### Headers\n\nHeaders are specified after the URL, each on a separate line:\n\n##### Example\n\n```\npost :1234/search\n\nContent-Type: application/json\nAuthorization: Bearer token\nUser-Agent: HTTP Script\nCache-Control: no-cache\n```\n\n#### Body\n\nThe body of the request is used for methods that accept a body (POST, PUT, PATCH) and should be terminated with a period (`.`):\n\n##### Example\n\n```\nPost :1234\n\n.body\n{\n  \"name\": \"user\",\n  \"password\": \"user12345\"\n}\n.\n```\n\n#### JavaScript\n\nJavaScript code can be included to execute during the request and should be terminated with a period (`.`) on the following line. The code has access to `response` and `this`, which contain information about the current request.\n\n##### Example\n\n```\ng :1234/user\n\n.js\nconsole.log(JSON.parse(this.body));\nconsole.log(response.data.user.name);\n.\n```\n\n#### Files\n\nTo send or save files, use `\u003c` for sending and `\u003e` for saving. Specify these after the URL and other parameters.\n\n##### Example\n\n```\np :1234/convert/png\n\n\u003c ./image.jpg\n\u003e ./image.png\n```\n\n### Request Cycle\n\nYou can chain requests one after another using `---` to separate each request. Additionally, you can define variables and use a shared state between requests, as well as set a base URL to simplify working with extensive APIs.\n\n#### Chaining Requests\n\nRequests can be separated by `---`:\n\n##### Example\n\n```\np :1234\n\n---\n\ng :1234\n\n---\n\nu :1234\n\n---\n\nd :1234\n```\n\n#### Shared States \u0026 Variables\n\nStates are defined in `this.state` and can be used as variables starting with `$`:\n\n```\nGET :1234\n\nUser-Agent: HTTP Script\n\n.js\nthis.state.userAgent = this.headers['User-Agent'];\n.\n\n---\n\nPOST :1234\n\nUser-Agent: $userAgent\n```\n\n#### Base URL\n\nThe base URL is automatically set if `this.state.baseUrl` is not defined, completing the URL if it starts with `/`:\n\n```\nGet httpbin.org/get\n\n---\n\nPost /post\n\n.js\nthis.state.baseUrl = 'reqres.in/api';\n.\n\n---\n\nGet /users/2\n```\n\n#### Default\n\nDefault is a variable that defines the request defaults\n\n```\nGet httpbin.org/get\n\n.js\n// In Node.js:\n// const b64 = Buffer.from('user:demo').toString('base64')\n\nconst b64 = btoa('user:demo')\nthis.state.b64 = b64\nthis.state.default.headers.authorization = `Basic ${b64}`\n.\n\n---\n\nGet /basic-auth/user/demo\n\n# Default Apply:\n# authorization: Basic $b64\nuser-agent: HTTP Script\n```\n\nThus adding both the user-agent header and\nthe authorization header\n\n### Contributing\n\nHi there!\n\nI'm really excited about your interest in contributing to my project! If you’d like to help out with ideas, fixes, or new features, I’d be thrilled to have your support. To get started, check out my contribution guide and see how you can make a difference.\n\nYou can find the details in the [CONTRIBUTING.md](CONTRIBUTING.md).\n\nThank you for considering contributing and helping to make the project even better!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrunodavi%2Fhttp-script","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrunodavi%2Fhttp-script","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrunodavi%2Fhttp-script/lists"}