Skip to content

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

@bberliner

Description

@bberliner

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions