{"id":28942885,"url":"https://github.com/alexrsagen/node-es6-request","last_synced_at":"2025-08-02T19:07:25.780Z","repository":{"id":57227200,"uuid":"54674914","full_name":"alexrsagen/node-es6-request","owner":"alexrsagen","description":"HTTP Request library written in ES6 for Node.js","archived":false,"fork":false,"pushed_at":"2020-06-23T08:50:49.000Z","size":66,"stargazers_count":6,"open_issues_count":1,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-07-11T15:58:39.192Z","etag":null,"topics":["es6","http","http-client","node-js","node-module","nodejs","pipe","promise"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexrsagen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-24T21:18:53.000Z","updated_at":"2022-04-06T19:43:45.000Z","dependencies_parsed_at":"2022-09-15T11:22:20.924Z","dependency_job_id":null,"html_url":"https://github.com/alexrsagen/node-es6-request","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alexrsagen/node-es6-request","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexrsagen%2Fnode-es6-request","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexrsagen%2Fnode-es6-request/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexrsagen%2Fnode-es6-request/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexrsagen%2Fnode-es6-request/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexrsagen","download_url":"https://codeload.github.com/alexrsagen/node-es6-request/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexrsagen%2Fnode-es6-request/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268439146,"owners_count":24250667,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"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":["es6","http","http-client","node-js","node-module","nodejs","pipe","promise"],"created_at":"2025-06-23T04:05:43.162Z","updated_at":"2025-08-02T19:07:25.742Z","avatar_url":"https://github.com/alexrsagen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-es6-request\nHTTP Request library written in ES6 for Node.js. Now with TypeScript definitions!\n\n**Warning! Only supports Node.js \u003e=8.0.0** (See \"Added in\" [here](https://nodejs.org/api/stream.html#stream_writable_destroy_error))\n\n## Installation\n```\nnpm i es6-request\n```\n\n## API\nFunctions that return a new `Request` instance:\n* `es6-request`.get(`url`)\n* `es6-request`.put(`url`)\n* `es6-request`.post(`url`)\n* `es6-request`.head(`url`)\n* `es6-request`.patch(`url`)\n* `es6-request`.delete(`url`)\n* `es6-request`.options(`url`)\n\n##### `Request`\n\n##### `Request`.query(`key`, `value`)\n\nAlternatively, **`Request`.query(`object`)**\n\n* `key` [\u0026lt;string\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) Query string key\n* `value` \u0026lt;any\u0026gt; Query string value\n* `object` [\u0026lt;Object\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) Query string key/value object\n\nThis function adds to the query string of the `url` or creates a new query string that will be added to the `url` before performing the reuqest.\n\nReturns `Request`\n\n##### `Request`.header(`key`, `value`)\n\nAlternatively, **`Request`.headers(`object`)**\n\n* `key` [\u0026lt;string\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) Header name\n* `value` \u0026lt;any\u0026gt; Header value\n* `object` [\u0026lt;Object\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) Header key/value object\n\nAdds a header to the request by the name of `key` and the content of `val` or adds the key/value headers from `object`.\n\nReturns `Request`\n\n##### `Request`.authBasic(`username`, `password`)\n\n* `username` [\u0026lt;string\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) Username\n* `password` [\u0026lt;string\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) Password\n\nAdds an `Authorization: Basic \u003ctoken\u003e` header to your request.\n\nReturns `Request`\n\n##### `Request`.authBearer(`bearer`)\n\n* `bearer` [\u0026lt;string\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) Bearer token\n\nAdds an `Authorization: Bearer \u003cbearer\u003e` header to your request.\n\nAdds options from a key/value object to the Node.js HTTP [options](https://nodejs.org/api/http.html#http_new_agent_options).\n\nReturns `Request`\n\n##### `Request`.option(`key`, `value`)\n\nAlternatively, **`Request`.options(`object`)**\n\n* `key` [\u0026lt;string\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) Option name\n* `value` \u0026lt;any\u0026gt; Option value\n* `object` [\u0026lt;Object\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) Option key/value object\n\nAdds an option or a key/value object of options to the Node.js HTTP [options](https://nodejs.org/api/http.html#http_new_agent_options).\n\nReturns `Request`\n\n##### `Request`.sendForm(`form`)\n\n* `form` [\u0026lt;Object\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) Form key/value object\n\nTransforms the `form` object into a querystring and sends the request as `application/x-www-form-urlencoded`.\n\nReturns a [\u0026lt;Promise\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\n\n##### `Request`.sendMultipart([`form`][, `files`][, `filesFieldNameFormat`][, `encoding`])\n\n* `form` [\u0026lt;Object\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) Form key/value object (field name/contents)\n* `files` [\u0026lt;Object\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) Files key/value object (filename/contents)\n* `filesFieldNameFormat`[\u0026lt;string\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) Multipart file field name (defaults to `files[%i]`)\n* `encoding` [\u0026lt;string\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) Multipart entity Content-Transfer-Encoding (defaults to `utf8`)\n\nTransforms the `form` and `files` into multipart form fields and sends the request as `multipart/form-data`.\n\nReturns a [\u0026lt;Promise\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\n\n##### `Request`.sendJSON(`data`)\n\n* `data` \u0026lt;any\u0026gt; Data that will be transformed into JSON\n\nTransforms the `data` into a JSON string and sends the request as `application/json`.\n\nReturns a [\u0026lt;Promise\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\n\n##### `Request`.write(`chunk`[, `encoding`][, `callback`])\n\n* `chunk` [\u0026lt;string\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) | [\u0026lt;Buffer\u0026gt;](https://nodejs.org/api/buffer.html#buffer_class_buffer)\n* `encoding` [\u0026lt;string\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)\n* `callback` [\u0026lt;Function\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)\n\nYou must run `Request`.start() before running this function. Directly writes to the request using [this](https://nodejs.org/api/http.html#http_request_write_chunk_encoding_callback) function from Node.js.\n\nReturns `Request`\n\n##### `Request`.send(`chunk`[, `encoding`][, `callback`])\n\n* `chunk` [\u0026lt;string\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) | [\u0026lt;Buffer\u0026gt;](https://nodejs.org/api/buffer.html#buffer_class_buffer)\n* `encoding` [\u0026lt;string\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)\n* `callback` [\u0026lt;Function\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)\n\nStarts a request, then directly writes to the it using [this](https://nodejs.org/api/http.html#http_request_write_chunk_encoding_callback) function from Node.js, then performs the request.\n\nReturns a [\u0026lt;Promise\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\n\n##### `Request`.start()\n\nStarts a request. After this function has been called, helper functions like `Request`.headers(), `Request`.header() and `Request`.query() will no longer work until the request has ended.\n\nReturns `Request`\n\n##### `Request`.pipe(`destination`)\n\nStarts the request if it is not already started. Pipes the response chunks to the destination stream using [this](https://nodejs.org/api/stream.html#stream_readable_pipe_destination_options) function from Node.js, then performs the request.\n\nReturns `Request`\n\n##### `Request`.perform()\n\nThis function ends a request. It is called by other functions like [Request.send()](#requestsend) and [Request.pipe()](#requestpipe).\n\nReturns a [\u0026lt;Promise\u0026gt;](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\n\n## Usage\n\n#### Simple GET Request\n```javascript\nconst request = require(\"es6-request\");\n\n// you can exchange \"get\" with \"head\", \"delete\" or \"options\" here\n// they all have the exact same API\nrequest.get(\"https://raw.githubusercontent.com/alexrsagen/node-es6-request/master/README.md\")\n.then(([body, res]) =\u003e {\n    console.log(body);\n    // should output this README file!\n});\n```\n\n#### POST Request\nThe following example will send a x-www-form-urlencoded request to the server containing keys and values from the json object.\n```javascript\nconst request = require(\"es6-request\");\n\n// you can exchange \"post\" with either \"put\" or \"patch\" here\n// they all have the exact same API\nrequest.post(\"http://api.somewebsite.com/endpoint\")\n.sendForm({\n  somekey: \"somevalue\"\n})\n.then(([body, res]) =\u003e {\n    // ...\n});\n```\nThis example will send a raw string to the server.\n```javascript\nconst request = require(\"es6-request\");\n\n// you can exchange \"post\" with either \"put\" or \"patch\" here\n// they all have the exact same API\nrequest.post(\"http://api.somewebsite.com/endpoint\")\n.send(\"i am a string, i will be sent to the server with a POST request.\")\n.then(([body, res]) =\u003e {\n    // ...\n});\n```\n\n#### Query string\nThis works the same way with any other request type.\n```javascript\nconst request = require(\"es6-request\");\n\n// sends a GET request to http://api.somewebsite.com/endpoint?this=that\u0026one=two\u0026three=four\nrequest.get(\"http://api.somewebsite.com/endpoint\")\n.query(\"this\", \"that\")\n.query({\n    \"one\": \"two\",\n    \"three\": \"four\"\n})\n.then(([body, res]) =\u003e {\n    // ...\n});\n```\n\n#### Headers\n```javascript\nconst request = require(\"es6-request\");\n\n// Sends a GET request with these headers:\n// {\n//     \"Accept\": \"application/json\",\n//     \"Header-Name\": \"header value\",\n//     \"Another-Header\": \"another value\"\n// }\nrequest.get(\"http://api.somewebsite.com/endpoint\");\n.header(\"Accept\", \"application/json\")\n.headers({\n    \"Header-Name\": \"header value\",\n    \"Another-Header\": \"another value\"\n})\n.then(([body, res]) =\u003e {\n    console.log(res.headers);\n    // ...\n});\n```\n\n#### Pipes\nThe following example POSTs all data you enter to STDIN to the local server we create, which then logs the data back to the console.\n```javascript\nconst request = require(\"es6-request\");\nconst server = require(\"http\").createServer((req, res) =\u003e {\n  req.setEncoding('utf8');\n  req.on('data', (chunk) =\u003e {\n    console.log(chunk);\n  });\n  req.on('end', () =\u003e {\n    res.end();\n  });\n}).listen(1337);\n\nprocess.stdin.pipe(request.post(\"http://localhost:1337\"));\n```\n\nThis example pipes the GitHub logo to a file named `logo.png`.\n```javascript\nconst request = require(\"es6-request\");\nconst fs = require(\"fs\");\n\nrequest.get(\"https://github.com/images/modules/logos_page/GitHub-Mark.png\").pipe(fs.createWriteStream(\"logo.png\")).perform();\n```\n\n#### Multipart forms\nThe following example POSTs a field and a file to a server using `multipart/form-data`\n```javascript\nconst request = require(\"es6-request\");\nconst fs = require(\"es6-fs\");\n\nfs.readFile(\"logo.png\")\n.then(contents =\u003e\n  request.post(\"http://api.somewebsite.com/endpoint\")\n  .sendMultipart({\n    somekey: \"somevalue\"\n  }, {\n    \"logo.png\": contents\n  }, \"files[%i]\", \"base64\")\n);\n```\n\nSample multipart form body that gets sent to the server:\n```\n----------------------------151a08730e1f\nMIME-Version: 1.0\nContent-Transfer-Encoding: base64\nContent-Disposition: form-data; name=\"somekey\"\n\nc29tZXZhbHVl\n----------------------------151a08730e1f\nMIME-Version: 1.0\nContent-Transfer-Encoding: base64\nContent-Disposition: form-data; name=\"files[0]\"; filename=\"logo.png\"\n\niVBORw0KGgoAAAA(trimmed 19073 characters...)\n----------------------------151a08730e1f--\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexrsagen%2Fnode-es6-request","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexrsagen%2Fnode-es6-request","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexrsagen%2Fnode-es6-request/lists"}