Polka: Package: Express-like Response Helpers

Created on 22 Jan 2018  路  12Comments  路  Source: lukeed/polka

Ported from #5:

Add a middleware package that attaches helpers directly to the `res` object?

This would mimic Express, potentially offering all/most of them.

This is a low(er) priority, but would definitely be helpful for those who can't live without the Express built-ins. 馃槅

Most helpful comment

Thanks! I'm trying to carve out a chunk of time so that I can finish the entire Polka 1.0 suite in a 1-2 week push. All the big pieces are done 鈥撀爅ust need some documentation and some more tests.

As for this issue specifically, some of the smaller utilities are _not_ done but they may not be needed at all. The bigger pieces of this issue left TBD are cookies & fresh

All 12 comments

Potentially required built-ins (must needed) have to be listed...?

Sorry, don't understand what you mean

IMHO a list of must needed Express built-ins need to be made. Can't implement all of them right?
And the ones that are lighter vs heavier on perf.

Would this be implemented as a middleware that would go on an use statement?

Because I kinda have something I would like to flesh out a bit more and maybe include here.

I have 85% of the response helpers done now :) right now, some of the "big" ones are their own packages (eg, send, sendfile, redirect) but the others are grouped together and available as their own exports. I think this will be a @polka/response package:

import { link, download } from '@polka/response';

polka()
  .get('*', (req, res) => {
    link(res, ...);
  })

These imports are just like the current "send" package. They operate independently/don't need to be used inside Polka at all.

I might also be re-exporting those bigger packages (send, redirect, etc) from this package too. Not sure yet.

Finally, and probably more importantly, there's a @polka/compat package that will auto-attach all response helpers so that you have a near-identical Express setup.

import compat from `@polka/compat`;

polka()
  .use(compat)
  .get((req, res) => {
    res.set('X-Foo', 'custom header');
    res.status(200).json({ foo: 123 });
  })

I haven't released his components yet in a @next tag yet simply because I'm not exactly sure how to subdivide all these behaviors in the sane way. I don't want to risk renaming items, moving functions, etc until things are a little more concrete

Both @polka/response and @polka/compat sound like really good ideas.

The only thing that's holding me back from switching to polka from express for old projects.

What is the status of this, @lukeed? Really looking forward to this!

Thanks! I'm trying to carve out a chunk of time so that I can finish the entire Polka 1.0 suite in a 1-2 week push. All the big pieces are done 鈥撀爅ust need some documentation and some more tests.

As for this issue specifically, some of the smaller utilities are _not_ done but they may not be needed at all. The bigger pieces of this issue left TBD are cookies & fresh

Glad to hear it! The main helper we need is res.redirect; is that included in 1.0?

Yes :)

@talentlessguy Please do not go around advertising your framework in issues. Good practice in general.

@lukeed I'm sorry, I just thought these extensions would be useful for ppl who use polka and have to rewrite them from scratch

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lagmanzaza picture lagmanzaza  路  4Comments

charleslxh picture charleslxh  路  3Comments

flawyte picture flawyte  路  7Comments

deadcoder0904 picture deadcoder0904  路  8Comments

motss picture motss  路  4Comments