https://github.com/eightyfive/koa-request-xhr
Express req.xhr equivalent for Koa
https://github.com/eightyfive/koa-request-xhr
Last synced: 6 months ago
JSON representation
Express req.xhr equivalent for Koa
- Host: GitHub
- URL: https://github.com/eightyfive/koa-request-xhr
- Owner: eightyfive
- Created: 2015-11-04T05:47:58.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-01-01T09:08:23.000Z (over 10 years ago)
- Last Synced: 2025-02-24T06:02:39.906Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# koa-request-xhr
This middleware simply sets a `xhr` boolean on koa's [`ctx.state`](https://github.com/koajs/koa/blob/master/docs/api/context.md#ctxstate) namespace.
This aims to be the equivalent of [Express `req.xhr`](http://expressjs.com/api.html#req.xhr)
## Installation
```
$ npm install koa-request-xhr --save
```
## Example
```js
var koa = require('koa');
var xhr = require('koa-request-xhr');
var app = koa();
app.use(xhr());
app.use(function *(){
if (this.state.xhr) {
this.body = { message: 'Hello World' };
} else {
this.body = 'Hello World';
}
});
app.listen(3000);
```