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

Accept Numbers as body in send() #1406

Closed
3 tasks done
artushin opened this issue Jul 11, 2017 · 8 comments
Closed
3 tasks done

Accept Numbers as body in send() #1406

artushin opened this issue Jul 11, 2017 · 8 comments

Comments

@artushin
Copy link

artushin commented Jul 11, 2017

  • Used appropriate template for the issue type
  • Searched both open and closed issues for duplicates of this issue
  • Title adequately and concisely reflects the feature or the bug

Feature Request

5.0 breaks the ability to send numbers as a body in send(). I'd like to add them back.

Use Case

Why do you want this?
Backwards compatibility. If an API is already written with Number responses (which are arguably valid JSON), 5.0 breaks the contract.

Example API

This should include code snippets and documentation for the proposed feature
.send(200, 5);

Are you willing and able to implement this?

"Yes" or, if "no", what can current contributors do to help you create a PR?
Yes. I guess booleans probably fall into the same category. I can add those too.

@retrohacker
Copy link
Member

Hey @artushin,

Thanks for pointing this regression out! I believe I introduced it when updating the way we handle optional parameters here: https://github.com/restify/node-restify/blob/5.x/lib/response.js#L273-L277

Is there a reliable way to differentiate between a body that is a Number and a status code? I.E. will a status code only be required when using a body of type Number as in resp.send(200, 200)?

@retrohacker
Copy link
Member

To clarify, we run into the problem where:

Clear: resp.send(200, '200')
Clear: resp.send('200')
Clear: resp.send(200, 200)
Ambiguous: resp.send(200)

@retrohacker
Copy link
Member

I'm labeling this as a bug since it was a regression and a feature since it is technically a "new" thing if we decide to formally support it. Also labeling it as needs discussion since, as it stands, this is introducing ambiguity into the API.

@artushin
Copy link
Author

artushin commented Jul 18, 2017 via email

@kokarn
Copy link

kokarn commented Aug 4, 2017

I think the last case should also be a status code.
If somebody want's to implement something like that they should probably specify a explicit status code.

@retrohacker
Copy link
Member

@yunong @rajatkumar @DonutEspresso thoughts?

@DonutEspresso
Copy link
Member

Agree with status code, I think it would be more confusing to break that API given the historical/legacy use cases.

@hekike
Copy link
Member

hekike commented Apr 10, 2018

Fixed by: #1609

@hekike hekike closed this as completed Apr 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants