{"id":25124645,"url":"https://github.com/sahneedev/ajax","last_synced_at":"2025-04-02T17:42:13.438Z","repository":{"id":53591467,"uuid":"336888009","full_name":"SahneeDEV/ajax","owner":"SahneeDEV","description":"A dependency-free utility library for making AJAX requests in JavaScript \u0026 TypeScript. 🌐","archived":false,"fork":false,"pushed_at":"2023-04-17T10:33:05.000Z","size":30,"stargazers_count":0,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T05:54:39.521Z","etag":null,"topics":["api","fetch","http","javascript","url"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SahneeDEV.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-02-07T20:57:15.000Z","updated_at":"2022-01-06T14:58:52.000Z","dependencies_parsed_at":"2023-07-18T16:21:38.645Z","dependency_job_id":null,"html_url":"https://github.com/SahneeDEV/ajax","commit_stats":null,"previous_names":["sahnee-de/ajax"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SahneeDEV%2Fajax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SahneeDEV%2Fajax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SahneeDEV%2Fajax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SahneeDEV%2Fajax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SahneeDEV","download_url":"https://codeload.github.com/SahneeDEV/ajax/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246863706,"owners_count":20846298,"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":["api","fetch","http","javascript","url"],"created_at":"2025-02-08T08:17:17.405Z","updated_at":"2025-04-02T17:42:13.416Z","avatar_url":"https://github.com/SahneeDEV.png","language":"TypeScript","readme":"# @sahnee/ajax\n\nA dependency-free utility library for making AJAX requests in JavaScript \u0026 TypeScript.\n\n## Installation\n\n```\nnpm install @sahnee/ajax\n```\n\n## Usage\n\nThis library provides a simple to use API to make AJAX calls using fetch. If your browser does not support fetch (e.g. IE11) you need to provide a polyfill on your end.\n\nThis readme will provide a short overview of many basic functions, however your are urged to read the documentation included in the source before using.\n\n### Simple AJAX request\n\nThe `ajax` funtcion is a thin wrapper over `fetch`:\n\n```js\nimport { ajax } from '@sahnee/ajax';\n\nconst response = await ajax('https://account.sahnee.dev/api/flow/public_key');\nconst publicKey = await response.text();\n// publicKey = ---- BEGIN PUBLIC KEY ---- \\n [...]\n```\n\nThe response is simply a plain JS `Response` in the same format as it would be returned by `fetch`.\n\n### JSON AJAX request\n\nThis is one of the primary reasons this library was created. JSON AJAX requests have a nice abstraction around them by using the `json` function.\n\n```js\nimport { json } from '@sahnee/ajax';\n\nconst todo = await json('https://jsonplaceholder.typicode.com/todos/1');\n// todo = { userId: 1, id: 1, title: \"delectus aut autem\", completed: false }\n```\n\nFurthermore it allows you to easily send JSON data aswell:\n\n\n```js\nimport { json } from '@sahnee/ajax';\n\nconst blogPost = await json('https://example.com/api/createBlogPost', {\n  method: 'POST',\n  json: {\n    title: 'HTTP requests in depth',\n    content: 'Lorem ipsum dolor sit amet [...]',\n    tags: ['http', 'tutorial']\n  }\n});\n// blogPost = whatever JSON your endpoint returned\n```\n\n### Flexible URL format\n\nSpecifying URLs can be annoying and a security risk if not done properly (query string injection, etc...). For this reason the library allows you to specify URLs as granular as possible while taking care of correctly escaping them.\n\nThe following examples all request data from the same URL `https://example.com/api/listUsers?page=42\u0026sortBy=name\u0026sortBy=mail`:\n\n```js\nimport { ajax } from '@sahnee/ajax';\n\najax('https://example.com/api/listUsers?page=42\u0026sortBy=name\u0026sortBy=mail');\najax({ url: 'https://example.com/api/listUsers', search: { page: 42, sortBy: ['name', 'mail'] } });\najax({ origin: 'https://example.com', url: ['api', 'listUsers'], search: { page: 42, sortBy: ['name', 'mail'] }});\n```\n\nEven more options are available:\n\n- `url`: A string specifying the relevative (to the current origin) or absolute URL of the resource. (A string or a list of URL components which will be escaped and joined)\n- `origin`: The origin domain the `url` is relative to. By default the current domain. (A string)\n- `username`: The username for making the request. (A string, for HTTP authentication)\n- `password`: The password for making the request. (A string, for HTTP authentication)\n- `protocol`: The protocol to use. (A string, only `http` and `https` are officially supported)\n- `port`: The port to use. (A number)\n- `hash`: The hash to use.\n- `search`: The search query parameters. (An object of strings to an URL component or a list of URL components)\n\nThere is also a function called `url` that simply returns the fully formatted URL without making any requests.\n\n### Default options\n\nYou can set default options that will be applied to every request in the `defaultInit` object:\n\n```js\nimport { defaultInit } from '@sahnee/ajax';\n\ndefaultInit.headers['x-auth'] = 'my-auth-token-123';\n```\n\nThe default options will also be applied to the result of the `url` function.\n\n## Important differences to fetch\n\n- By default non success status codes will raise an `APIError`. This can be disabled by setting the `allowNonSuccessStatusCode` option to `true`.\n- The `json` function fully abstracts the `Response` object away from the user.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsahneedev%2Fajax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsahneedev%2Fajax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsahneedev%2Fajax/lists"}