Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bjufre/koa-isajax
Middleware for koajs 2 to check if the incoming request is an Ajax request.
https://github.com/bjufre/koa-isajax
Last synced: 3 months ago
JSON representation
Middleware for koajs 2 to check if the incoming request is an Ajax request.
- Host: GitHub
- URL: https://github.com/bjufre/koa-isajax
- Owner: bjufre
- Created: 2016-12-18T10:59:24.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2016-12-18T14:27:17.000Z (over 7 years ago)
- Last Synced: 2024-03-20T00:11:58.456Z (3 months ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 2
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Lists
- koa-awesome - koa-isajax - Express req.xhr equivalent for Koa 2 applications. (Packages / Middleware)
README
# koa-isajax
Express `req.xhr` equivalent for Koa 2 applications.
Middleware for Koa 2 that sets a boolean on the `ctx.state` on whether or not the request is and Ajax request.This middleware is the equivalent to [Express `req.xhr`.](http://expressjs.com/en/api.html#req.xhr)
## Installation
`$ npm install koa-isajax --save`## Example
```javascript
import Koa from 'koa';
import isajax from 'koa-isajax';const app = new Koa();
app.use(isajax());
app.use(async (ctx) => {
if (ctx.state.xhr) {
// Ajax request.
} else {
// Not ajax request.
}
});app.listen(3000);
```