{"_id":"zyos","_rev":"31-ed3d90eca9acd091e027eb49808af8c3","name":"zyos","dist-tags":{"latest":"1.0.0-beta.6"},"versions":{"1.0.0-beta.2":{"name":"zyos","version":"1.0.0-beta.2","author":{"name":"Sittha Manittayakul"},"license":"MIT","_id":"zyos@1.0.0-beta.2","maintainers":[{"name":"6ma-606","email":"zyxma.6666@hotmail.com"}],"homepage":"https://github.com/6MA-606/Zyos#readme","bugs":{"url":"https://github.com/6MA-606/Zyos/issues"},"dist":{"shasum":"099e1ba5dadafdb0a721f032d7911baf63e0457e","tarball":"https://registry.npmjs.org/zyos/-/zyos-1.0.0-beta.2.tgz","fileCount":7,"integrity":"sha512-0dEjv0oKaJCxwRwmOpHD3hksrqd1qrEkjuYNQE4EJ8Kdkr3lnm5iZSo6ZkTD9Vl6nuhzfI/OoHX5bH5t4KonhQ==","signatures":[{"sig":"MEUCIQDJUGtucq7vLFGYC1tb8YD/ANcZHUxy7/HW0FdH6do8UgIgOvMHO0XcFhuUPGKnyEEyjZFtvCFaDhyrdcDN6mhi67s=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":31417},"main":"index.js","types":"./index.d.ts","gitHead":"35e3b05e6d073377f7c39835acc3877280b1d7f5","scripts":{"test":"exit 0"},"_npmUser":{"name":"6ma-606","email":"zyxma.6666@hotmail.com"},"repository":{"url":"git+https://github.com/6MA-606/Zyos.git"},"_npmVersion":"10.8.1","description":"This is a simple package for make window.fetch easier to use.","directories":{},"_nodeVersion":"20.16.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/zyos_1.0.0-beta.2_1729386803080_0.101200475968936","host":"s3://npm-registry-packages"}},"1.0.0-beta.4":{"name":"zyos","version":"1.0.0-beta.4","author":{"name":"Sittha Manittayakul"},"license":"MIT","_id":"zyos@1.0.0-beta.4","maintainers":[{"name":"6ma-606","email":"zyxma.6666@hotmail.com"}],"homepage":"https://github.com/6MA-606/Zyos#readme","bugs":{"url":"https://github.com/6MA-606/Zyos/issues"},"dist":{"shasum":"ae7f89e3f76359facce14e951578b68917373b68","tarball":"https://registry.npmjs.org/zyos/-/zyos-1.0.0-beta.4.tgz","fileCount":7,"integrity":"sha512-FDS/bOySLB/idCRC7W566j7slsXRo5353URe6H18ZiWX/ELP58DwFLXsTHedOzGHcqJcOaRCsWGN+I24Bwjz6w==","signatures":[{"sig":"MEYCIQDpF6fSDWlQt13NlDEFF2Qqdr258PwiyLPHVnRz7EngegIhAI4KmfyOARoVL8sFs3IRKQCWR8J8yq+ToT6L5yb80gG6","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":32771},"main":"index.js","types":"./index.d.ts","gitHead":"de956529bbe4af2ace2cbfc86a691338dc7d6014","scripts":{"test":"exit 0"},"_npmUser":{"name":"6ma-606","email":"zyxma.6666@hotmail.com"},"repository":{"url":"git+https://github.com/6MA-606/Zyos.git"},"_npmVersion":"10.8.1","description":"This is a simple package for make window.fetch easier to use.","directories":{},"_nodeVersion":"20.16.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/zyos_1.0.0-beta.4_1731101845832_0.6118577798480753","host":"s3://npm-registry-packages"}},"1.0.0-beta.5":{"name":"zyos","version":"1.0.0-beta.5","author":{"name":"Sittha Manittayakul"},"license":"MIT","_id":"zyos@1.0.0-beta.5","maintainers":[{"name":"6ma-606","email":"zyxma.6666@hotmail.com"}],"homepage":"https://github.com/6MA-606/Zyos#readme","bugs":{"url":"https://github.com/6MA-606/Zyos/issues"},"dist":{"shasum":"a24c6c7b28e78706392d5096728d4bfcf860a3d2","tarball":"https://registry.npmjs.org/zyos/-/zyos-1.0.0-beta.5.tgz","fileCount":13,"integrity":"sha512-DPsYxjqaZwrwqWXUgaLgS97+a6RR0vYfXnCm/moiJXt4iZBgOKMFwGrLnNpX1zorofLKo2snMJLcgnJ1Ewlq/Q==","signatures":[{"sig":"MEYCIQC8p6cyqNTJkI07p6XQKKGvWB63bNTBko+KI0SCtrLFOgIhAN6AqJ50V1tekGIP2tk61/KvKEuyoYvk7XtElQUKPafq","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":36521},"main":"index.js","types":"./index.d.ts","gitHead":"5362a117ca474f83eadb904c91eec1c1bc4596f8","scripts":{"test":"exit 0"},"_npmUser":{"name":"6ma-606","email":"zyxma.6666@hotmail.com"},"repository":{"url":"git+https://github.com/6MA-606/Zyos.git"},"_npmVersion":"10.8.1","description":"This is a simple package for make window.fetch easier to use.","directories":{},"_nodeVersion":"20.16.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/zyos_1.0.0-beta.5_1731609690696_0.006723507877619994","host":"s3://npm-registry-packages"}},"1.0.0-beta.6":{"name":"zyos","version":"1.0.0-beta.6","main":"index.js","repository":{"url":"git+https://github.com/6MA-606/Zyos.git"},"scripts":{"test":"exit 0"},"author":{"name":"Sittha Manittayakul"},"license":"MIT","description":"This is a simple package for make window.fetch easier to use.","_id":"zyos@1.0.0-beta.6","gitHead":"be4055a8112385a9ff05355379719c9287069af0","types":"./index.d.ts","bugs":{"url":"https://github.com/6MA-606/Zyos/issues"},"homepage":"https://github.com/6MA-606/Zyos#readme","_nodeVersion":"20.16.0","_npmVersion":"10.8.1","dist":{"integrity":"sha512-35fMubrsKS9jSpiIcUJqxwF7OcQEHt3yTk0qUHLQXgmSfmeUqBetEhdesAwq+EbFKYBqLd7gtaqyYVo02hOJKQ==","shasum":"a3632fe330230d2001853dad99266afdd61989a9","tarball":"https://registry.npmjs.org/zyos/-/zyos-1.0.0-beta.6.tgz","fileCount":11,"unpackedSize":36475,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDoo+vnE5iNV1H1y/ESiTshV6XbVFWsjQxi1qnv2JpwwwIgAiVhgeBlM8bjox97u92sAxBXWyiYVATM0m5dO1NSB/U="}]},"_npmUser":{"name":"6ma-606","email":"zyxma.6666@hotmail.com"},"directories":{},"maintainers":[{"name":"6ma-606","email":"zyxma.6666@hotmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/zyos_1.0.0-beta.6_1733906079902_0.6757419951470103"},"_hasShrinkwrap":false}},"time":{"created":"2024-10-19T23:27:56.120Z","modified":"2024-12-11T08:34:40.270Z","1.0.0":"2024-08-28T07:25:21.764Z","1.0.1":"2024-08-29T08:13:19.738Z","1.0.2":"2024-08-29T08:33:30.956Z","1.1.0":"2024-08-29T16:23:49.335Z","1.1.1":"2024-08-30T08:57:56.198Z","1.1.3":"2024-08-30T14:03:30.873Z","1.1.4":"2024-08-30T14:27:12.250Z","1.1.5":"2024-08-30T15:33:47.129Z","1.2.0":"2024-09-04T10:28:43.054Z","1.2.1":"2024-09-15T19:19:51.160Z","1.3.0":"2024-09-17T04:46:57.101Z","1.4.0":"2024-09-29T18:58:04.417Z","1.5.0-beta":"2024-10-08T22:27:47.592Z","1.5.0-beta.1":"2024-10-18T15:42:24.598Z","1.5.0-beta.1001":"2024-10-18T15:58:08.824Z","1.5.0-beta.1002":"2024-10-18T16:09:15.045Z","1.0.0-beta.1":"2024-10-19T23:27:56.309Z","1.0.0-beta.2":"2024-10-20T01:13:23.290Z","1.0.0-beta.3":"2024-10-20T01:23:15.674Z","1.0.0-beta.4":"2024-11-08T21:37:26.014Z","1.0.0-beta.5":"2024-11-14T18:41:30.961Z","1.0.0-beta.6":"2024-12-11T08:34:40.110Z"},"bugs":{"url":"https://github.com/6MA-606/Zyos/issues"},"author":{"name":"Sittha Manittayakul"},"license":"MIT","homepage":"https://github.com/6MA-606/Zyos#readme","repository":{"url":"git+https://github.com/6MA-606/Zyos.git"},"description":"This is a simple package for make window.fetch easier to use.","maintainers":[{"name":"6ma-606","email":"zyxma.6666@hotmail.com"}],"readme":"# Important Announcement\r\nI decided to **republish** `zyos` on npm. The reason is that I think zyos is **not stable enough** to be published as to `1.0.0`. I will publish the `1.0.0-beta.0001` at **20 October 2024 around 12:00 AM (UTC+7)**. I will also update the documentation and the codebase. I hope you understand my decision. Thank you 😊.\r\n\r\n<div align=\"center\">\r\n<h1>Zyos</h1>\r\n\r\n<a href=\"#\">\r\n  <img src=\"https://github.com/user-attachments/assets/19cf1b13-dd7d-425a-9bdf-8acd770efaec\" width=\"220px\" />\r\n</a>\r\n\r\n[![npm](https://img.shields.io/npm/v/zyos?style=for-the-badge&colorB=51C838)](https://www.npmjs.com/package/zyos)\r\n[![npm-download](https://img.shields.io/npm/d18m/zyos?style=for-the-badge)](https://www.npmjs.com/package/zyos)\r\n[![license](https://img.shields.io/badge/MIT-orange?style=for-the-badge&label=License)](#)\r\n\r\nSimplifying `window.fetch()` for easier HTTP requests.\r\n\r\n</div>\r\n\r\n# What is Zyos?\r\n\r\nZyos is a small library that wraps around `window.fetch()` to make it simpler to use for HTTP requests. It offers a straightforward API for working with requests and responses.\r\n\r\n> **Note:** Zyos is designed for modern browsers that support `window.fetch()`. If you're targeting older browsers, you might need a polyfill.\r\n\r\n> **Note:** Zyos works best with JSON data. If you need to handle other data types, you'll need to customize the library.\r\n\r\n> **Note:** This library was created by **Sittha Manittayakul, a 3rd-year student at King Mongkut's University of Technology Thonburi (KMUTT)**, as part of the INT222 project for the 1st semester of the 2024 academic year.\r\n\r\n## Installation\r\n\r\n```bash\r\nnpm install zyos\r\n```\r\n\r\n## Usage\r\n\r\n### Simple Request\r\n\r\n**GET Request**\r\n\r\n```javascript\r\nimport zyos from 'zyos'\r\n\r\n// Make a GET request (GET is the default method)\r\nconst response = await zyos.fetch('https://jsonplaceholder.typicode.com/posts/1')\r\nconsole.log(response.data)\r\n```\r\n\r\n**POST Request**\r\n\r\n```javascript\r\nimport zyos from 'zyos'\r\n\r\n// Make a POST request\r\nconst response = await zyos.fetch('https://jsonplaceholder.typicode.com/posts', {\r\n  method: 'POST',\r\n  body: {\r\n    title: 'foo',\r\n    body: 'bar',\r\n    userId: 1\r\n  }\r\n})\r\nconsole.log(response.data)\r\n```\r\n\r\n---\r\n\r\n### Request Options\r\n\r\n**headers: object**\r\n\r\nYou can pass headers in the request by providing an object with key-value pairs. The header name is the key, and the value is the header’s content.\r\n\r\nIf you set custom headers that match the default headers, your custom headers will override them. The default headers are:\r\n\r\n`{ 'Content-Type': 'application/json' }`\r\n\r\n```javascript\r\nimport zyos from 'zyos'\r\n\r\n// Make a GET request with custom headers\r\nconst response = await zyos.fetch('https://jsonplaceholder.typicode.com/posts/1', {\r\n  headers: {\r\n    'Your-Header': 'Your-Value'\r\n  }\r\n})\r\nconsole.log(response.data)\r\n```\r\n\r\n<br />\r\n\r\n**method: string**\r\n\r\nYou can set the HTTP method (GET, POST, PUT, DELETE, etc.) as a string.\r\n\r\nThe default method is `'GET'`.\r\n\r\n```javascript\r\nimport zyos from 'zyos'\r\n\r\n// Specify the method for the request\r\nconst response = await zyos.fetch('https://jsonplaceholder.typicode.com/posts/1', {\r\n  method: 'GET' // or 'POST', 'PUT', etc.\r\n})\r\nconsole.log(response.data)\r\n```\r\n\r\n<br />\r\n\r\n**body: object**\r\n\r\nTo send data with the request, pass an object as the body. This is useful for POST or PUT requests.\r\n\r\n```javascript\r\nimport zyos from 'zyos'\r\n\r\n// Send a POST request with data\r\nconst response = await zyos.fetch('https://jsonplaceholder.typicode.com/posts', {\r\n  method: 'POST',\r\n  body: {\r\n    title: 'foo',\r\n    body: 'bar',\r\n    userId: 1\r\n  }\r\n})\r\nconsole.log(response.data)\r\n```\r\n\r\n<br />\r\n\r\n**useToken: boolean**\r\n\r\nIf your request requires a token (for example, for authentication), set `useToken` to `true`. Zyos will check for a token in the following order:\r\n\r\n1. The `token` option\r\n2. The `tokenGetter` function\r\n3. The default token (`defaultToken`) or token getter function (`defaultTokenGetter`) defined in the configuration\r\n\r\nIf not defined, Zyos will check `alwaysUseToken` setting in the configuration instead.\r\n\r\nThis option will override the `alwaysUseToken` setting in the configuration.\r\n\r\n```javascript\r\nimport zyos from 'zyos'\r\n\r\n// Make a request with a token\r\nconst response = await zyos.fetch('https://jsonplaceholder.typicode.com/posts/1', {\r\n  useToken: true\r\n})\r\nconsole.log(response.data)\r\n```\r\n\r\n<br />\r\n\r\n**token: string**\r\n\r\n**_Warning: Hardcoding tokens is not safe and should be avoided._**\r\n\r\nYou can manually provide a token by setting the `token` option. This is used only if `useToken` is `true`.\r\n\r\n```javascript\r\nimport zyos from 'zyos'\r\n\r\n// Request with a hardcoded token\r\nconst response = await zyos.fetch('https://jsonplaceholder.typicode.com/posts/1', {\r\n  useToken: true,\r\n  token: 'your-token'\r\n})\r\nconsole.log(response.data)\r\n```\r\n\r\n<br />\r\n\r\n**tokenGetter: function**\r\n\r\nInstead of hardcoding the token, you can pass a function that returns the token. This function is called when making the request.\r\n\r\n```javascript\r\nimport zyos from 'zyos'\r\n\r\n// Request using a token from a function\r\nconst response = await zyos.fetch('https://jsonplaceholder.typicode.com/posts/1', {\r\n  useToken: true,\r\n  tokenGetter: () => {\r\n    return 'your-token'\r\n  }\r\n})\r\nconsole.log(response.data)\r\n```\r\n\r\n<br />\r\n\r\n**computedFunction: function**\r\n\r\nYou can provide a function to process or modify the response data before it is returned.\r\n\r\n```javascript\r\nimport zyos from 'zyos'\r\n\r\n// Modify response data before it's returned\r\nconst response = await zyos.fetch('https://jsonplaceholder.typicode.com/posts/1', {\r\n  computedFunction: (data) => {\r\n    data.timestamp = Date.now()\r\n    return data // Return the modified data\r\n  }\r\n})\r\nconsole.log(response.data) // { userId: 1, id: 1, title: '...', body: '...', timestamp: 1630000000000 }\r\n```\r\n\r\n<br />\r\n\r\n**timeout: number**\r\n\r\nYou can set a timeout for the request in milliseconds. If the request takes longer than the timeout, it will be rejected.\r\n\r\n```javascript\r\nimport zyos from 'zyos'\r\n\r\n// Modify response data before it's returned\r\nconst response = await zyos.fetch('https://jsonplaceholder.typicode.com/posts/1', {\r\n  timeout: 5000 // 5 seconds\r\n})\r\nconsole.log(response.data) // { userId: 1, id: 1, title: '...', body: '...', timestamp: 1630000000000 }\r\n```\r\n\r\n<br />\r\n\r\n**retry: number**\r\n\r\nYou can set the number of times to retry the request if it fails. The default is `0` (no retries).\r\n\r\n> If you set a retry and a timeout, the timeout will be applied to each retry.\r\n\r\n```javascript\r\nimport zyos from 'zyos'\r\n\r\n// Modify response data before it's returned\r\nconst response = await zyos.fetch('https://jsonplaceholder.typicode.com/posts/1', {\r\n  retry: 3 // Retry 3 times\r\n})\r\nconsole.log(response.data) // { userId: 1, id: 1, title: '...', body: '...', timestamp: 1630000000000 }\r\n```\r\n\r\n---\r\n\r\n### Defining Config\r\n\r\nYou can set default values for all requests using `zyos.defineConfig()`.\r\n\r\n```javascript\r\nimport zyos from 'zyos'\r\n\r\n// Define default settings for requests\r\nzyos.defineConfig({\r\n  alwaysUseToken: true, // default is false\r\n  alwaysEncodeURI: true, // default is true\r\n\r\n  /* Default is\r\n    defaultHeaders: {\r\n      'Content-Type': 'application/json'\r\n    }\r\n  */\r\n  defaultHeaders: {\r\n    'Your-Header': 'Your-Value'\r\n  },\r\n  defaultMethod: 'GET', // default is 'GET'\r\n  defaultToken: 'your-token', // default is null\r\n  defaultTokenGetter: () => { // default is null\r\n    return 'your-token from getter'\r\n  },\r\n  loggings: 'all', // default is 'all'\r\n  globalResponseHandling: (response) => { // default is null\r\n    console.log(response)\r\n  }\r\n})\r\n```\r\n\r\nYou can define default headers, the default method, and token options. These will be applied if specific settings are not provided in the request.\r\n","readmeFilename":"README.md"}