-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Feature request: output full HTTP request and response in a JSON structure #1007
Comments
Thanks for the suggestion, @hughpv. I’ve been considering this for a while. Initial thoughts
Hypothetical example$ http -v --output-format=json example.org // Exchange
{
"request": {
"headers": {
"Foo": "Bar"
},
"body": "…"
},
"response": {
"headers": {
"Foo": "Bar"
},
"body": {
"result": "ok"
}
}
} |
Awesome ideas; love them all. Let me just expand a little on my use case -- I have it in mind to build a test suite that, in addition to testing functionality, also captures output for use in documentation, e.g.: = Example Request
----
include:request.http[]
----
= Example Response
----
include:response.http[]
---- ... where Thus what I'm looking for is essentially a "verbatim" or "raw" option. All the other stuff makes sense but the raw output was the main idea I came here with. Thanks! |
I see, so for your use case, the structured headers would be a complication, because you would have to manually un-structure them for the docs? |
Correct. :) But I could definitely see where some users would find structured headers quite useful. |
This comment was marked as spam.
This comment was marked as spam.
HAR would be a great format to use for this |
This would be extremely helpful for some testing use cases (I've currently got a really ugly shell function that mimics this with vanilla Some thoughts on the format:
Borrowing language from ExamplesRawCommand:
Output: {
"request": {
"uri": {
"raw": "http://example.com:8081/test?foo=bar"
},
"method": "POST",
"headers": {
"raw": "Accept: application/json\r\nContent-Type: application/json"
},
"body": {
"text": "Lorem ipsum dolor sit amet"
}
},
"response": {
"code": 201,
"status": "Created",
"headers": {
"raw": "Content-Type: application/json\r\nContent-Length: 42"
},
"body": {
"text": "consectetur adipiscing elit"
}
}
} Structured/ParsedCommand:
Output: {
"request": {
"uri": {
"json": {
"scheme": "http",
"host": "example.com",
"port": 8081,
"path": "/test",
"query": {
"foo": [
"bar"
]
}
}
},
"method": "POST",
"headers": {
"json": {
"Accept": [
"application/json"
],
"Content-Type": [
"application/json"
]
}
},
"body": {
"base64": "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQ="
}
},
"response": {
"code": 201,
"headers": {
"text": [
"Content-Type: application/json",
"Content-Length: 42"
]
},
"body": {
"json": "\"consectetur adipiscing elit\""
}
}
} MixedCommand:
Output: {
"request": {
"uri": {
"raw": "http://example.com:8081/test?foo=bar"
},
"method": "POST"
},
"response": {
"code": 201,
"headers": {
"raw": "Accept: application/json\r\nContent-Type: application/json",
"json": {
"Accept": [
"application/json"
],
"Content-Type": [
"application/json"
]
}
},
"body": {
"base64": "Y29uc2VjdGV0dXIgYWRpcGlzY2luZyBlbGl0"
}
}
} Sorry for the edits, I kept hitting the key for "submit" instead of "newline+indent" 🤦🏻 |
I would love to capture the full HTTP request and response in a JSON structure so I can extract the various parts programmatically without parsing the plaintext output.
For example:
The text was updated successfully, but these errors were encountered: