-
Notifications
You must be signed in to change notification settings - Fork 32
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
Allow to pass status code into response methods #583
Comments
found whilst working on realworld, would be great to not have to add an extra line to specify status code |
should we just overloaded methods? i ask because what if we end up wanting to add headers easily |
@crookse it's a good idea actually, but im generally against overloads cause the main function gets messy, like what if we then wanna add something else? text(text: string, status = 200): void
text(text: string, headers = []): void
text(text: string, status = 200, headers = [])
text(text: string, param?: number | string[]) {
if
if
if
if duplicate that for each response method, what ive actually been thinking about instead after reading your comment, is something like text(text: string, status = 200, headers = []) {
this.setResponse(text, status, headers)
}
json(json: object, status = 200, headers = []) {
this.setResponse(JSON.stringify(json), status, headers)
}
...
#setResponse(body: BodyInit | null, status = 200, headers = []) {
this.status = status
if (headers.length) {
headers.forEach(h => this.headers.set(h.name, h.value))
}
tis.body = body
} what are your thoughts? if you feel storngly about overloads then we can try it out |
nah i don't have a preference. just thought overloads would make it easier. |
eg
response.json({ name: 'drash' }, 200)
orresponse.text("Invalid request", 200)
The text was updated successfully, but these errors were encountered: