{"id":15253533,"url":"https://github.com/ladjs/koa-isajax","last_synced_at":"2025-10-05T19:30:15.600Z","repository":{"id":57126134,"uuid":"434596644","full_name":"ladjs/koa-isajax","owner":"ladjs","description":"Middleware for koajs 2 to check if the incoming request is an Ajax request.","archived":false,"fork":true,"pushed_at":"2021-12-03T13:07:01.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-11T10:41:20.066Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"bjufre/koa-isajax","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ladjs.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":"2021-12-03T12:56:58.000Z","updated_at":"2021-12-03T13:07:04.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ladjs/koa-isajax","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fkoa-isajax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fkoa-isajax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fkoa-isajax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ladjs%2Fkoa-isajax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ladjs","download_url":"https://codeload.github.com/ladjs/koa-isajax/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235432243,"owners_count":18989483,"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-09-29T21:05:23.429Z","updated_at":"2025-10-05T19:30:15.137Z","avatar_url":"https://github.com/ladjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# koa-isajax\n\nExpress `req.xhr` equivalent for Koa 2 applications.\nMiddleware for Koa 2 that sets a boolean on the `ctx.state` on whether or not the request is and Ajax request.\n\nThis middleware is the equivalent to [Express `req.xhr`.](http://expressjs.com/en/api.html#req.xhr)\n\n## Installation\n`$ npm install koa-isajax --save`\n\n## Options\n\n`isajax(setVary)` accepts an argument `setVary` which is a String that defaults to `'X-Requested-With'`.  If you pass `false`, then `ctx.vary(setVary)` will not be called immediately.\n\nThis sets the `Vary` header so that AJAX and HTML responses on the same page do not conflict:\n\n* \u003chttps://stackoverflow.com/questions/1975416/what-is-the-function-of-the-vary-accept-http-header/1975677#1975677\u003e\n* \u003chttps://stackoverflow.com/questions/9956255/chrome-displays-ajax-response-when-pressing-back-button/10117752#10117752\u003e\n\n## Example\n\n```javascript\nimport Koa from 'koa';\nimport isajax from 'koa-isajax';\n\nconst app = new Koa();\n\napp.use(isajax());\napp.use(async (ctx) =\u003e {\n    if (ctx.state.xhr) {\n        // Ajax request.\n    } else  {\n        // Not ajax request.\n    }\n});\n\napp.listen(3000);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fladjs%2Fkoa-isajax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fladjs%2Fkoa-isajax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fladjs%2Fkoa-isajax/lists"}