You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+38Lines changed: 38 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -569,6 +569,44 @@ There are, however, a few main differences. Polka does not support or offer:
569
569
app.get('/users/*', _ => {});
570
570
```
571
571
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
0 commit comments