{"id":20302014,"url":"https://github.com/forthedamn/net4j","last_synced_at":"2025-04-11T13:36:55.582Z","repository":{"id":36806287,"uuid":"173886046","full_name":"forthedamn/net4j","owner":"forthedamn","description":"Pluggable \u0026 Promise based HTTP client for the browser and node.js","archived":false,"fork":false,"pushed_at":"2023-01-03T17:18:41.000Z","size":894,"stargazers_count":3,"open_issues_count":44,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T09:49:28.390Z","etag":null,"topics":["axios","http-client","promise","request","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/forthedamn.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":"2019-03-05T06:13:14.000Z","updated_at":"2022-11-09T12:12:40.000Z","dependencies_parsed_at":"2023-01-17T05:00:49.217Z","dependency_job_id":null,"html_url":"https://github.com/forthedamn/net4j","commit_stats":null,"previous_names":[],"tags_count":90,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forthedamn%2Fnet4j","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forthedamn%2Fnet4j/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forthedamn%2Fnet4j/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forthedamn%2Fnet4j/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/forthedamn","download_url":"https://codeload.github.com/forthedamn/net4j/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248410215,"owners_count":21098772,"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":["axios","http-client","promise","request","typescript"],"created_at":"2024-11-14T16:28:49.059Z","updated_at":"2025-04-11T13:36:55.562Z","avatar_url":"https://github.com/forthedamn.png","language":"TypeScript","readme":"# net4j\n\nPluggable \u0026 Promise based HTTP client for the browser and node.js\n\n## Features\n\n* Support Typescript\n* Pluggable, easily unified processing\n* Dependency injection\n* Make XMLHttpRequests from the browser\n* Make http requests from node.js\n* Supports the Promise API\n* Automatic transforms for JSON data\n\n![gif](http://s0.meituan.net/bs/tempfs/file/zhongguoxin/cap0309.gif)\n\n## Browser Support\n\n![Chrome](https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png) | ![Firefox](https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png) | ![Safari](https://raw.github.com/alrra/browser-logos/master/src/safari/safari_48x48.png) | ![Opera](https://raw.github.com/alrra/browser-logos/master/src/opera/opera_48x48.png) | ![Edge](https://raw.github.com/alrra/browser-logos/master/src/edge/edge_48x48.png) | ![IE](https://raw.github.com/alrra/browser-logos/master/src/archive/internet-explorer_9-11/internet-explorer_9-11_48x48.png) |\n--- | --- | --- | --- | --- | --- |\nLatest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 11 ✔ |\n\n[![Browser Matrix](https://saucelabs.com/open_sauce/build_matrix/axios.svg)](https://saucelabs.com/u/axios)\n\n\n## Install\n\n```bash\n$ npm install net4j\n\n$ yarn add net4j\n```\n\n## Example\n\n### Normal Request\n\nPerforming a `GET` request\n\n```ts\nimport Net from 'net4j';\n\nconst net = new Net();\n\n// Type merge,so that /api/v2/goods will be typed\ndeclare module 'net4j' {\n  interface IGetRoute {\n    '/api/v2/goods': {\n      request: {\n        id: number\n      }\n      response: {\n        data: {\n          GoodsInfo\n        } \n      }\n    },\n  }\n}\n\n// `GET` request\n// result will be typed with {data: {GoodsInfo}}\nconst result = await net.get('/api/v2/goods');\n```\n\n### With plugins\n\n```ts\nimport Net from 'net4j';\nimport { message, Modal } from 'antd';\nimport NetLog from 'net4j-log-plugin';\nimport NetSuccess, { SuccessConfig } from 'net4j-success-plugin';\nimport NetLoading, { LoadingConfig } from 'net4j-loading-plugin';\nimport NetException, { ExceptionConfig } from 'net4j-exception-plugin';\n\n\ndeclare module 'net4j' {\n  // Merge plugin config to net4j config,then you can use it in every requst in net4j\n  interface Config extends SuccessConfig, LoadingConfig, ExceptionConfig {};\n\n  // Type merge,so that /api/v2/goods will be typed\n  interface IGetRoute {\n    '/api/v2/goods': {\n      request: {\n        id: number\n      }\n      response: {\n        data: {\n          GoodsInfo\n        } \n      }\n    },\n  }\n}\n\n// Exception code to message\n// Exception code comes from http status,response result.code,promise reject error.code\nconst codeMsgMap = {\n  404: 'page not found',\n  403: function() {\n    // In this time, tipsComponent will not show.\n    redirect('/login');\n  },\n  5400: 'Name repeat'\n}\n\nconst net = new Net(plugins: [\n  // Inject own log,so the exception and other operations will be reported\n    new NetLog({\n      log: {\n        info: myLogger.info,\n        error: myLogger.error,\n      },\n    }),\n    // When request is pending, message loading will display and close when request finish\n    new NetLoading({\n      loading: message.loading,\n    }),\n    // When request completed successfully, message.success will display\n    new NetSuccess({\n      tipsComponent: message.success,\n    }),\n    // When request get exception，error modal will display and error will be auto reported\n    new NetException({\n      tipsComponent: Modal.error,\n      codeMsgMap,\n    }),\n  ]);\n\n// `GET` request\n// result will be typed with {data: {GoodsInfo}}\nconst result = await net.get('/api/v2/goods', {params: {id: 123}});\n```\n\n## Plugins\n\n* [net4j-success-plugin](https://github.com/forthedamn/net4j/tree/master/packages/net4j-success-plugin): Unified set 「success tip」 when request completed successfully.\n* [net4j-loading-plugin](https://github.com/forthedamn/net4j/tree/master/packages/net4j-loading-plugin): Unified set 「loading toast」 when request pending.\n* [net4j-exception-plugin](https://github.com/forthedamn/net4j/tree/master/packages/net4j-exception-plugin): Unified set 「error tip」 when request get exception.\n* [net4j-log-plugin](https://github.com/forthedamn/net4j/tree/master/packages/net4j-log-plugin): Inject 「log libary」 in request, it will be used when request get exception or other critical operations\n\n### How to write a plugin\n\n```ts\nexport interface Plugin {\n  beforeRequest?(e?: Error, config?: AxiosRequestConfig, lib?: ILib): Config | Promise\u003cConfig\u003e;\n  // Inject libs to whole request, so other plugins use these libs \n  applyLib?(lib: { [key: string]: any}): { [key: string]: any};\n  afterRequest?\u003cT = any\u003e(e?: Error, response?: T, lib?: ILib): T | Promise\u003cAxiosResponse\u003cError\u003e\u003e;\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fforthedamn%2Fnet4j","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fforthedamn%2Fnet4j","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fforthedamn%2Fnet4j/lists"}