2

I would like to use httpie to generate documentation for a REST web services. The idea would be to have a text containing sample requests with comments

'ping the server','http -v get :8080/ping'
'submit document','http -v post :8080/document name=asdf' 

A script would then execute the requests and capture the nicely formatted output in a document.

Is there a way to do that?

LouisChiffre
  • 691
  • 7
  • 15

2 Answers2

1

I don't know a way to make it via httpie, but there is a way to grab formatted output from bash to html: see this question or use HTML::FromANSI perl module or aha tool. There are many similar tools, choose the most suitable for you.

Community
  • 1
  • 1
injecto
  • 829
  • 1
  • 10
  • 23
  • 1
    Thanks! You are right. What I did: you can force httpie to output ansi strings --pretty=all then use a third party tool to transform it in html. I used ansi2html. – LouisChiffre Jul 27 '14 at 17:05
1

You could also use Pygments CLI (pip install pygments). That should provide cleaner HTML, and it also gives you the option to choose any from the many Pygments styles.

{

# Stylesheet:
echo '<style>'
pygmentize -S default -f html 
echo '</style>'

# Request HTTP headers as HTML:
http --print=H httpbin.org/post hello=world | pygmentize -f html -l http /dev/stdin

# JSON request body as HTML:
http --print=B httpbin.org/post hello=world | pygmentize -f html -l json /dev/stdin

}  > request.html

Output:

enter image description here

<style>
…
</style>
<div class="highlight"><pre><span class="nf">POST</span> <span class="nn">/post</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span>
<span class="na">Content-Length</span><span class="o">:</span> <span class="l">18</span>
<span class="na">Accept-Encoding</span><span class="o">:</span> <span class="l">gzip, deflate</span>
<span class="na">Accept</span><span class="o">:</span> <span class="l">application/json</span>
<span class="na">User-Agent</span><span class="o">:</span> <span class="l">HTTPie/0.8.0</span>
<span class="na">Host</span><span class="o">:</span> <span class="l">httpbin.org</span>
<span class="na">Content-Type</span><span class="o">:</span> <span class="l">application/json; charset=utf-8</span>
</pre></div>
<div class="highlight"><pre><span class="p">{</span><span class="nt">&quot;hello&quot;</span><span class="p">:</span> <span class="s2">&quot;world&quot;</span><span class="p">}</span>
</pre></div>
Jakub Roztocil
  • 15,930
  • 5
  • 50
  • 52