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

Projects
None yet
2 participants
@jmwerner
Contributor

jmwerner commented Oct 18, 2017

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

This comment has been minimized.

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).

jmwerner and others added some commits Nov 22, 2018

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

1 check was pending

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
@hadley

This comment has been minimized.

Member

hadley commented Dec 4, 2018

Thanks @jmwerner!

@jmwerner jmwerner deleted the jmwerner:post_precision_patch branch Dec 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment