Skip to content

Commit 99f4fe9

Browse files
committed
docs: note polka.handler == express() instead;
- Closes #63
1 parent d6296ed commit 99f4fe9

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

readme.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,44 @@ There are, however, a few main differences. Polka does not support or offer:
569569
app.get('/users/*', _ => {});
570570
```
571571

572+
6) **Polka instances are not (directly) the request handler.**
573+
574+
Most packages in the Express ecosystem expect you to pass your `app` directly into the package. This is because `express()` returns a middleware signature directly.
575+
576+
In the Polka-sphere, this functionality lives in your application's [`handler`](#handlerreq-res-parsed) instead.
577+
578+
Here's an example with [`supertest`](https://github.com/visionmedia/supertest), a popular testing utility for Express apps.
579+
580+
```js
581+
const request = require('supertest');
582+
const send = require('@polka/send-type');
583+
584+
const express = require('express')();
585+
const polka = require('polka')();
586+
587+
express.get('/user', (req, res) => {
588+
res.status(200).json({ name: 'john' });
589+
});
590+
591+
polka.get('/user', (req, res) => {
592+
send(res, 200, { name: 'john' });
593+
});
594+
595+
function isExpected(app) {
596+
request(app)
597+
.get('/user')
598+
.expect('Content-Type', /json/)
599+
.expect('Content-Length', '15')
600+
.expect(200);
601+
}
602+
603+
// Express: Pass in the entire application directly
604+
isExpected(express);
605+
606+
// Polka: Pass in the application `handler` instead
607+
isExpected(polka.handler);
608+
```
609+
572610

573611
## License
574612

0 commit comments

Comments
 (0)