question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: output full HTTP request and response in a JSON structure

See original GitHub issue

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:

http --output-full-json ...
{
  "request": {
    "headers": "Accept: application/json\r\nContent-Type: application/json",
    "body": "<request body here, escaped/encoded as necessary to work as a string value>"
  },
  "response": {
    "headers": "201 Created\r\nContent-Type: application/json\r\nContent-Length: 42",
    "body": "<response body here, escaped/encoded as necessary to work as a string value>"
  }
}

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
jakubroztocilcommented, Dec 21, 2020

Thanks for the suggestion, @hughpv. I’ve been considering this for a while.

Initial thoughts

  • Output options should be respected.
  • With --all, an Array of exchanges is printed instead of a single object.
  • What about binary bodies? Apply base64 encoding like httpbin.org? Let user choose to skip/base64-encode?
  • JSON body, when valid, could be embedded into the structure directly (i.e., not as string).
  • A structured object for headers would be nice, but we should support multiple headers of the same name somehow.
  • UI — --output-format which could be raw (default) + json + potentially more in the future.
  • User can always pipe to jq but consider supporting simple selectors directly. Something like --select=response.headers.content-type. These would work on the JSON structure so when used, then --output-format=json would be implied. Need to consider the multi-exchange scenario (where index might be needed).

Hypothetical example

$ http -v --output-format=json  example.org
// Exchange
{
  "request": {
    "headers": {
      "Foo": "Bar"
    },
    "body": "…"
  },
  "response": {
    "headers": {
      "Foo": "Bar"
    },
    "body": {
      "result": "ok"
    }
  }
}
1reaction
hughpvcommented, Dec 21, 2020

Correct. 😃 But I could definitely see where some users would find structured headers quite useful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON requests and responses - Atlassian Developer
To make a request with JSON, the appropriate HTTP headers are: ... the following command attempts to authenticate a user by password with...
Read more >
response.json() - Python requests - GeeksforGeeks
response.json() returns a JSON object of the result (if the result was written in JSON format, if not it raises an error). Python...
Read more >
Request and Response JSON Reference | Alexa Skills Kit
The request body sent to your service is in JSON format. In this example, the AudioPlayer directive has been requested, but the Display.RenderTemplate...
Read more >
Python requests response print in JSON format U' is added to ...
You can use encode() method to convert unicode strings to ascii strings like this : import requests import json headers={ "accept": ...
Read more >
Working with JSON - Learn web development | MDN
JavaScript Object Notation (JSON) is a standard text-based format for ... request using the fetch() function, and this returns a Response ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found