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

Change default precision for POST requests #490

Merged
merged 5 commits into from
Dec 4, 2018

Conversation

jmwerner
Copy link
Contributor

Hello! This PR was inspired by losing decimal precision via a POST request, e.g.

> POST("http://httpbin.org/post", body = list(a = .8675309), encode = "json")
Response [http://httpbin.org/post]
  Date: 2017-10-18 17:46
  Status: 200
  Content-Type: application/json
  Size: 490 B
{
  "args": {}, 
  "data": "{\"a\":0.8675}", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "application/json, text/xml, application/xml, */*", 
    "Accept-Encoding": "gzip, deflate", 
    "Connection": "close", 
    "Content-Length": "12", 
...

This is happening because of the default jsonlite::toJSON behavior which can be easily fixed by passing a json to body in lieu of this PR if the dev team believes the default behavior should not be changed.

> POST("http://httpbin.org/post", body = jsonlite::toJSON(list(a = .8675309), digits = 10), encode = "json")
Response [http://httpbin.org/post]
  Date: 2017-10-18 17:46
  Status: 200
  Content-Type: application/json
  Size: 471 B
{
  "args": {}, 
  "data": "{\"a\":[0.8675309]}", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "application/json, text/xml, application/xml, */*", 
    "Accept-Encoding": "gzip, deflate", 
    "Connection": "close", 
    "Content-Length": "17", 
...

Please let me know if any changes are necessary. Thanks!

@hadley
Copy link
Member

hadley commented Nov 22, 2018

Thanks - this seems like a reasonable change to me.

Can you please add a bullet to NEWS? It should briefly describe the change and end with (@yourname, #issuenumber).

@hadley hadley merged commit 396aa6e into r-lib:master Dec 4, 2018
@hadley
Copy link
Member

hadley commented Dec 4, 2018

Thanks @jmwerner!

@jmwerner jmwerner deleted the post_precision_patch branch December 6, 2018 05:39
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

Successfully merging this pull request may close these issues.

2 participants