{"id":15364507,"url":"https://github.com/xadillax/spidex","last_synced_at":"2025-04-15T07:31:07.944Z","repository":{"id":13311194,"uuid":"15997691","full_name":"XadillaX/spidex","owner":"XadillaX","description":"A web requester for node.js.","archived":false,"fork":false,"pushed_at":"2024-10-18T02:55:38.000Z","size":159,"stargazers_count":25,"open_issues_count":0,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-12T07:46:42.257Z","etag":null,"topics":["http","https","javascript","requester"],"latest_commit_sha":null,"homepage":"http://xcoder.in/","language":"TypeScript","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/XadillaX.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":"2014-01-17T11:11:39.000Z","updated_at":"2024-10-18T02:55:42.000Z","dependencies_parsed_at":"2022-08-25T18:20:30.567Z","dependency_job_id":null,"html_url":"https://github.com/XadillaX/spidex","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XadillaX%2Fspidex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XadillaX%2Fspidex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XadillaX%2Fspidex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XadillaX%2Fspidex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/XadillaX","download_url":"https://codeload.github.com/XadillaX/spidex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249026727,"owners_count":21200499,"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":["http","https","javascript","requester"],"created_at":"2024-10-01T13:12:02.522Z","updated_at":"2025-04-15T07:31:07.919Z","avatar_url":"https://github.com/XadillaX.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Spidex\n\n[![npm version](https://img.shields.io/npm/v/spidex.svg)](https://npmjs.org/spidex)\n[![npm downloads](https://img.shields.io/npm/dm/spidex.svg)](https://npmjs.org/spidex)\n[![Build Status](https://github.com/XadillaX/spidex/workflows/Node.js%20CI/badge.svg)](https://github.com/XadillaX/spidex/actions)\n[![Coverage Status](https://img.shields.io/coveralls/XadillaX/spidex/master.svg)](https://coveralls.io/github/XadillaX/spidex?branch=master)\n\nSpidex is a versatile web requester for Node.js and browsers, designed to simplify HTTP requests with a clean and\nintuitive API.\n\n## Features\n\n- Supports both Node.js and browser environments.\n- Handles GET, POST, PUT, DELETE and other methods.\n- Customizable request options including headers, timeouts, and charsets.\n- Built-in support for various character encodings.\n- Hessian v2 protocol support (Node.js only).\n- Event-based error handling.\n\n## Installation\n\nInstall Spidex using npm:\n\n```bash\nnpm install spidex --save\n```\n\n## Usage\n\n### Basic Request\n\n```js\nconst spidex = require('spidex');\n\nspidex.get('https://api.example.com/data', (content, statusCode, responseHeaders) =\u003e {\n  console.log('Response:', content);\n  console.log('Status:', statusCode);\n  console.log('Headers:', responseHeaders);\n}).on('error', err =\u003e {\n  console.error('Error:', err);\n});\n```\n\n### Request with Options\n\n```js\nspidex.post('https://api.example.com/users', {\n  data: JSON.stringify({ username: 'john_doe', email: 'john@example.com' }),\n  header: { 'Content-Type': 'application/json' },\n  charset: 'utf8',\n  timeout: 5000\n}, (content, statusCode, responseHeaders) =\u003e {\n  console.log('User created:', content);\n}).on('error', (err) =\u003e {\n  console.error('Error creating user:', err);\n});\n```\n\n### Supported Basic HTTP Methods\n\nSpidex supports the following HTTP methods:\n\n- `spidex.get(url, [options], [callback])`\n- `spidex.post(url, [options], [callback])`\n- `spidex.put(url, [options], [callback])`\n- `spidex.delete(url, [options], [callback])`\n\nEach method returns an EventEmitter that emits an 'error' event if an error occurs.\n\n### Supported Other HTTP Methods\n\n- `spidex.method(url, method, [options], [callback])`\n\n### Request Options\n\nThe `options` object can include the following properties:\n\n- `data`: Request body (string, object, or Buffer)\n- `header`: Custom request headers\n- `charset`: Character encoding (e.g., 'utf8', 'gbk', 'binary', etc.)\n- `timeout`: Total request timeout in milliseconds\n- `responseTimeout`: Response timeout in milliseconds\n- `requestTimeout`: Request timeout in milliseconds\n\n### Parsing Cookies\n\nSpidex provides a utility function to parse cookies from response headers:\n\n```js\nconst cookies = spidex.parseCookies(responseHeaders);\nconsole.log('Parsed cookies:', cookies);\n```\n\n### User Agent Management\n\nYou can get or set the default User-Agent string:\n\n```js\n// Get the current User-Agent\nconst currentUA = spidex.getDefaultUserAgent();\n\n// Set a custom User-Agent\nspidex.setDefaultUserAgent('MyApp/1.0');\n```\n\n### Hessian v2 Support (Node.js only)\n\nSpidex supports Hessian v2 protocol for Node.js environments:\n\n```js\nspidex.hessianV2('http://hessian.example.com/api', 'methodName', [arg1, arg2], (err, result) =\u003e {\n  if (err) {\n    console.error('Hessian request failed:', err);\n    return;\n  }\n  console.log('Hessian result:', result);\n});\n```\n\n## TypeScript Support\n\nSpidex includes TypeScript definitions. You can import and use it in TypeScript projects:\n\n```ts\nimport * as spidex from 'spidex';\n\nspidex.get('https://api.example.com/data', (content, statusCode, responseHeaders) =\u003e {\n  console.log('Typed response:', content);\n});\n```\n\n## Error Handling\n\nAll Spidex methods return an EventEmitter that emits an 'error' event. You can handle errors by listening to this event:\n\n```js\nspidex.get('https://api.example.com/data')\n  .on('error', (err) =\u003e {\n    console.error('Request failed:', err);\n  });\n```\n\n## License\n\nSpidex is released under the MIT License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxadillax%2Fspidex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxadillax%2Fspidex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxadillax%2Fspidex/lists"}