Skip to content

For cURL escaping of body content, single quotes should be used to improve readability #72

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

Closed
bberliner opened this issue Aug 15, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@bberliner
Copy link

The Postman app, without these code generators enabled, will escape the JSON body for a cURL request using single-quotes, which makes the body easily readable when copy/pasting the cURL example into docs or scripts. For example, here is what the normal Postman app might shoe for a cURL request that includes some JSON:

curl -X POST \
  https://example.com/api/command \
  -H 'Accept: application/json' \
  -H 'Authorization: Basic TzJbGNtdA==' \
  -H 'Content-Type: application/json' \
  -H 'X-Request-ID: 1b3d12ad-e2f5-442e-99bb-bbea58936683' \
  -d '{
    "action": "query",
    "target": {
        "features": [
            "versions",
            "profiles",
            "pairs"
        ]
    }
}
'

Note that it is using single-quotes to pass the Headers and Body content to the cURL command-line. As such, there is very little backslash escaping and readability is high. Furthermore, by not adding all the double-quote escapes to the JSON body content, I can copy/paste it directly into something else, since it is just JSON (and not JSON with a bunch of weird escaping, which is not valid JSON).

If I enable this experimental code generator, the result is decidedly less readable, since the code-generators cURL support chooses to use double-quotes, causing much more unnecessary escaping of the JSON:

curl -X POST "https://example.com/api/command" \
    -H "Authorization: Basic TzJbGNtdA==" \
    -H "Content-Type: application/json" \
    -H "Accept: application/json" \
    -H "X-Request-ID: 1b3d12ad-e2f5-442e-99bb-bbea58936683" \
    -d "{
    \"action\": \"query\",
    \"target\": {
        \"features\": [
            \"versions\",
            \"profiles\",
            \"pairs\"
        ]
    }
}"

If I copy/paste this JSON body content into jsonlint.com, you will see that it is no longer valid JSON due to all the extra backslash escaping.

As such, I'd like to revert the code-generators back to using the single-quote for sanitizing the headers and body content. I have a fix for this and will submit a pull request in the next couple weeks for review.

@umeshp7
Copy link
Contributor

umeshp7 commented Nov 5, 2019

@bberliner We have fixed this issue in #92 and is available on the latest Postman App.

Closing this issue for now. Feel free to reopen/create new issue if needed.

@umeshp7 umeshp7 closed this as completed Nov 5, 2019
@bberliner
Copy link
Author

@umeshp7 Thanks so much! I'll take a look as soon as I can update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants