{"id":13571866,"url":"https://github.com/indexzero/http-agent","last_synced_at":"2025-07-06T20:05:44.844Z","repository":{"id":955335,"uuid":"738932","full_name":"indexzero/http-agent","owner":"indexzero","description":"A simple agent for performing a sequence of http requests in node.js","archived":false,"fork":false,"pushed_at":"2013-05-02T07:37:44.000Z","size":143,"stargazers_count":94,"open_issues_count":6,"forks_count":15,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-09T22:03:48.826Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://github.com/indexzero/http-agent","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/indexzero.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-06-25T05:19:51.000Z","updated_at":"2024-07-03T09:12:42.000Z","dependencies_parsed_at":"2022-07-05T23:32:47.561Z","dependency_job_id":null,"html_url":"https://github.com/indexzero/http-agent","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/indexzero/http-agent","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indexzero%2Fhttp-agent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indexzero%2Fhttp-agent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indexzero%2Fhttp-agent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indexzero%2Fhttp-agent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/indexzero","download_url":"https://codeload.github.com/indexzero/http-agent/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indexzero%2Fhttp-agent/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263966173,"owners_count":23536814,"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":"2024-08-01T14:01:07.373Z","updated_at":"2025-07-06T20:05:44.820Z","avatar_url":"https://github.com/indexzero.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# http-agent\n\nA simple agent for performing a sequence of http requests in node.js\n\n## Installation\n\n### Installing npm (node package manager)\n\u003cpre\u003e\n  curl http://npmjs.org/install.sh | sh\n\u003c/pre\u003e\n\n### Installing http-agent\n\u003cpre\u003e\n  npm install http-agent\n\u003c/pre\u003e\n\n## Usage \n\nThere are several way to use http-agent: \n\n1. Simple: Pass it a host and an array of strings to visit all of those URLs.\n2. Complex: Pass it a host and an array of JSON objects representing all relevant parameters (method, request body, etc.)\n3. Iterator: Each time the 'next' event is raised by an agent, you have the opportunity to add or remove URLs you wish to visit. In this sense  \n\n### Using http-agent to visit a set of URLs on a single host with 'GET'\n\u003cpre\u003e\n  var util = require('util'),\n      httpAgent = require('path/to/http-agent/lib');\n  \n  var agent = httpAgent.create('graph.facebook.com', ['apple', 'facebook', 'google']);\n  \n  agent.addListener('next', function (e, agent) {\n    // Simple usage: Just output the raw\n    // HTML returned from each request\n    util.puts(agent.body);\n    agent.next();\n  });\n  \n  agent.addListener('stop', function (e, agent) {\n    util.puts('Agent has completed visiting all urls');\n  });\n  \n  // Start the agent\n  agent.start();\n\u003c/pre\u003e\n\n### Using http-agent to visit a set of URLs on a single host with complex parameters\nSince http-agent is based on top of request, it can take a set of JSON objects for request to use. If you're looking for more documentation about what parameters are relevant to http-agent, see [request][0] which http-agent is built on top of. \n\n\u003cpre\u003e\n  var util = require('util'),\n      httpAgent = require('path/to/http-agent/lib');\n  \n  var options = [\n    {\n      method: 'GET',\n      uri: 'apple'\n    },\n    {\n      method: 'GET',\n      uri: 'facebook'\n    },\n    {\n      method: 'GET',\n      uri: 'http://google.com/'\n    }\n  ];\n  var agent = httpAgent.create('graph.facebook.com', options);\n  \n  agent.addListener('next', function (e, agent) {\n    // Simple usage: Just output the raw\n    // HTML returned from each request\n    util.puts(agent.body);\n    agent.next();\n  });\n  \n  agent.addListener('stop', function (e, agent) {\n    util.puts('Agent has completed visiting all urls');\n  });\n  \n  // Start the agent\n  agent.start();\n\u003c/pre\u003e\n\n### Using http-agent as an iterator over webpages\nEach time an instance of http-agent raises the 'next' event the agent is passed back as a parameter. That allows us to change the control flow of pages each time a page is visited. The agent is also passed back to other important events such as 'stop' and 'back'.\n\u003cpre\u003e\n  var util = require('util'),\n      httpAgent = require('path/to/http-agent/lib');\n  \n  var agent = httpAgent.create('graph.facebook.com', ['apple', 'facebook', 'google']),\n      addPage = true;\n  \n  agent.addListener('next', function (e, agent) {\n    if (addPage) {\n      // The agent will now also visit 'http://graph.facebook.com/yahoo'\n      agent.addUrl('yahoo');\n      addPage = false;\n    }\n\n    // Simple usage: Just output the raw\n    // HTML returned from each request\n    util.puts(agent.body);\n    agent.next();\n  });\n  \n  agent.addListener('stop', function (e, agent) {\n    util.puts('Agent has completed visiting all urls');\n  });\n  \n  // Start the agent\n  agent.start();\n\u003c/pre\u003e\n\n## Run Tests\n\u003cpre\u003e\n  vows test/*-test.js --spec\n\u003c/pre\u003e\n\n#### Author: [Charlie Robbins](http://www.charlierobbins.com);\n\n[0]: https://github.com/mikeal/request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findexzero%2Fhttp-agent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Findexzero%2Fhttp-agent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findexzero%2Fhttp-agent/lists"}