We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Right now, every endpoint can only return one thing, but what if I want to type multiple things, linked to status codes?
Like, instead of just
listPublications: GET `/publications/${'category'}` .response(PublicationsList),
It would be nice if we could do something like
import { StatusCodes } from 'rest-ts-core'; const ErrorModel = rt.Record({ message: rt.String, code: rt.Number, }); /// .... listPublications: GET `/publications/${'category'}` .response(StatusCodes.OK, PublicationsList) .response(StatusCodes.NOT_FOUND, rt.Void) .response(StatusCodes.INTERNAL_ERROR, ErrorModel),
So then, in my api implementation, I could have some helpers to type the returns to status codes like
.listPublications((req, res) => { try { const publicationsList = await getPublicationsList(); if (publicationsList) { return StatusCodes.ok(publicationsList); } else { return StatusCodes.notFound(); } } catch (err) { return StatusCodes.internalError({message: 'Something failed', code: 123}) } })
The text was updated successfully, but these errors were encountered:
This is a niche use case, although it makes complete sense.
There is some other work I'd like to prioritise before getting into this kind of refinement.
Sorry, something went wrong.
No branches or pull requests
Right now, every endpoint can only return one thing, but what if I want to type multiple things, linked to status codes?
Like, instead of just
It would be nice if we could do something like
So then, in my api implementation, I could have some helpers to type the returns to status codes like
The text was updated successfully, but these errors were encountered: