{"id":27392222,"url":"https://github.com/samt/http-post","last_synced_at":"2025-09-05T22:34:45.333Z","repository":{"id":4823864,"uuid":"5977712","full_name":"samt/http-post","owner":"samt","description":"This utility extends the functionality of the 'http' library in stock node.js. It returns a post request function in a very similar way to node's http.get(). It supports both normal urlencoded payloads and multipart/form-data.","archived":false,"fork":false,"pushed_at":"2016-07-12T20:33:40.000Z","size":8,"stargazers_count":17,"open_issues_count":8,"forks_count":11,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-13T21:18:15.307Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"sinatra/sinatra","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/samt.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":"2012-09-27T05:52:20.000Z","updated_at":"2019-05-27T23:01:38.000Z","dependencies_parsed_at":"2022-07-21T13:32:24.150Z","dependency_job_id":null,"html_url":"https://github.com/samt/http-post","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samt%2Fhttp-post","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samt%2Fhttp-post/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samt%2Fhttp-post/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samt%2Fhttp-post/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samt","download_url":"https://codeload.github.com/samt/http-post/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248782256,"owners_count":21160717,"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","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":[],"created_at":"2025-04-13T21:18:19.255Z","updated_at":"2025-04-13T21:18:19.773Z","avatar_url":"https://github.com/samt.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# http-post\n\nThis utility extends the functionality of the `http` library in stock node.js\nproviding a post request function in the same fashion of node's [http.get()](http://nodejs.org/api/http.html#http_http_get_options_callback).\n\nIn the same style as `http.get()`, this function calls `req.end()` automatically\n\n## Installing\n\n\tnpm install http-post\n\n## Usage and parameters\n\n\thttp-post(options, data[, files[, callback]])\n\nor\n\n\thttp-post(options, data[, callback])\n\n### options\n\nOptions are the same as the ones for [http.request()](http://nodejs.org/api/http.html#http_http_request_options_callback)\nexcept `method` will always be forced to `POST`. Note that `options` can be\nreplaced with the full URI of the request similar to `http.get` allowing for\neven greater flexibility in your post requests.\n\n### data\n\nData should be key/value pairs of form data. This does not handle file data,\nsee the `files` option below for more information on uploading files.\n\n\tvar data = {\n\t\tname: \"Sam\",\n\t\temail: \"sam@emberlabs.org\",\n\t\tgender: \"m\",\n\t\tlanguages: [\n\t\t\t\"C\",\n\t\t\t\"C++\",\n\t\t\t\"Java\",\n\t\t\t\"JavaScript\",\n\t\t\t\"PHP\",\n\t\t\t\"Python\"\n\t\t]\n\t}\n\nPass it an empty array if you do not need to send any form data.\n\n### files\n\nThis param is another JavaScript object that can contain many files to be posted\n\n\tvar files = [\n\t\t{\n\t\t\tparam: \"img\",\n\t\t\tpath: \"./assets/mycoolimage.png\"\n\t\t},\n\t\t{\n\t\t\tparam: \"somefile\",\n\t\t\tname: \"mydata.txt\",\n\t\t\tpath: \"C:\\\\Users\\\\Sam\\\\Documents\\\\asdf.txt\"\n\t\t}\n\t]\n\nYou may chose to specify an optional `name` in your array. It will override the\nfile name as it exists in the filesystem and name it the name you specified for\nthe request.\n\n### callback\n\nCallback is the same from [http.request()](http://nodejs.org/api/http.html#http_http_request_options_callback).\nIt accepts an instance of [http.ClientResponce](http://nodejs.org/api/http.html#http_http_clientresponse)\nthat has been created during the time of the request.\n\n## Return\n\nReturns an instance of [http.ClientRequest](http://nodejs.org/api/http.html#http_class_http_clientrequest)\n\n## Examples\n\nSetting up\n\n\tvar http = require('http');\n\thttp.post = require('http-post');\n\nPosting data\n\n\thttp.post('http://localhost/postscript.php', { name: 'Sam', email: 'sam@emberlabs.org' }, function(res){\n\t\tres.setEncoding('utf8');\n\t\tres.on('data', function(chunk) {\n\t\t\tconsole.log(chunk);\n\t\t});\n\t});\n\nPosting a file\n\n\tvar files = [\n\t\t{\n\t\t\tparam: \"file\",\n\t\t\tpath: \"./assets/img/something.png\"\n\t\t}\n\t];\n\t\n\thttp.post('http://localhost/postscript.php', [], files, function(res){\n\t\t//...\n\t});\n\nPosting multiple files\n\n\tvar files = [\n\t\t{\n\t\t\tparam: \"file\",\n\t\t\tpath: \"./assets/img/something.png\"\n\t\t},\n\t\t{\n\t\t\tparam: \"junk\",\n\t\t\tpath: \"/home/sam/hello.txt\"\n\t\t}\n\t];\n\t\n\thttp.post('http://localhost/postscript.php', [], files, function(res){\n\t\t// ...\n\t});\n\nPosting data and files\n\n\tvar data = {\n\t\tname: 'Sam',\n\t\tdrink: 'coffee'\n\t};\n\t\n\tvar files = [\n\t\t{\n\t\t\tparam: \"file\",\n\t\t\tpath: \"./assets/img/something.png\"\n\t\t},\n\t\t{\n\t\t\tparam: \"junk\",\n\t\t\tpath: \"/home/sam/hello.txt\"\n\t\t}\n\t];\n\t\n\thttp.post('http://localhost/postscript.php', data, files, function(res){\n\t\t// ...\n\t});\n\n## License\n\n[The MIT License](http://opensource.org/licenses/mit-license.php)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamt%2Fhttp-post","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamt%2Fhttp-post","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamt%2Fhttp-post/lists"}