Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package: Express-like Response Helpers #14

Open
lukeed opened this issue Jan 21, 2018 · 12 comments
Open

Package: Express-like Response Helpers #14

lukeed opened this issue Jan 21, 2018 · 12 comments
Milestone

Comments

@lukeed
Copy link
Owner

lukeed commented Jan 21, 2018

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. 😆

@r0mflip
Copy link

r0mflip commented Apr 27, 2018

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

@lukeed
Copy link
Owner Author

lukeed commented Apr 27, 2018

Sorry, don't understand what you mean

@r0mflip
Copy link

r0mflip commented Apr 27, 2018

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.

@lukeed lukeed added this to the 1.0.0 milestone Dec 11, 2018
@lukeed lukeed mentioned this issue Dec 18, 2018
@guilhermeoc97
Copy link

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.

@lukeed
Copy link
Owner Author

lukeed commented May 24, 2019

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

@char
Copy link

char commented Jul 6, 2019

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.

@jhwheeler
Copy link

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

@lukeed
Copy link
Owner Author

lukeed commented Sep 20, 2019

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 – just 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

@jhwheeler
Copy link

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

@lukeed
Copy link
Owner Author

lukeed commented Sep 21, 2019

Yes :)

@lukeed
Copy link
Owner Author

lukeed commented Dec 8, 2020

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

Repository owner deleted a comment from talentlessguy Dec 8, 2020
@talentlessguy
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants