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

Typed request #13

Open
sualko opened this issue Jan 23, 2022 · 2 comments
Open

Typed request #13

sualko opened this issue Jan 23, 2022 · 2 comments

Comments

@sualko
Copy link
Contributor

sualko commented Jan 23, 2022

Thanks for this small little, but handy middleware. Great work 👏

I extended the default request interface to have a strongly typed parameter and thought, maybe this is also useful for others, or maybe it could even be integrated.

import type { NextApiRequest, NextApiResponse } from 'next'

export interface ValidatedApiRequest<Body = any, Query extends NextApiRequest['query'] = NextApiRequest['query']> extends NextApiRequest {
    body: Body
    query: Query
}

const query = Joi.object({
    id: Joi.string().required(),
});

async function handler(
  req: ValidatedApiRequest<undefined, {id: string}>,
  res: NextApiResponse
) {
//...
}

export default validator({query}, handler;
@sergioalvz
Copy link
Member

Hi, @sualko! Thanks for taking the time to open this issue and explain your findings :-) I'd be open to exploring this since it may help us with #9.

@sualko
Copy link
Contributor Author

sualko commented Jan 24, 2022

That sounds great. I will write some lines to the other issue, because I want the same as the author 😄

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

2 participants