Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixing rendering of cURL multiline body, new-lines in PHP and Python,…

… NodeJS on new-lines for readability
  • Loading branch information...
commit ee2752cddfd1eca52ac49465430e987695782efa 1 parent 9f707a4
Jakub Korál kuba-kubula authored

Showing 4 changed files with 30 additions and 17 deletions. Show diff stats Hide diff stats

  1. +1 2  curl.html
  2. +8 4 nodejs.html
  3. +1 1  php.html
  4. +20 10 python.html
3  curl.html
@@ -2,7 +2,6 @@
2 2 <p class="ioDesc">Request</p>
3 3 <pre class="incoming"><code class="language-bash">curl --include<% if @headers: %><% for header,value of @headers: %> --header <%= @helpers.escape "#{header}: #{value}" %><% end %> \
4 4 <% end %><% if @method isnt 'GET' or @body: %> --request <%= @method %> \
5   - <% end %><%if @method isnt 'GET' and (@contentType is "text/html" or @contentType is "text/plain"): %> --data "<%= ((@helpers.escape line)[1..-2] + "\n" for line in @body)[0..-2] %>" \
6   - <% else if @body: %> --data <%= @helpers.escape @body %> \
  5 + <% end %><% if @body: %> --data <%= @helpers.escape @body %> \
7 6 <% end %>"<%= @apiUrl %><%= @url %>"</code></pre>
8 7 </section>
12 nodejs.html
@@ -5,12 +5,16 @@
5 5 request("<%= @apiUrl %><%= @url %>", function (error, response, body) {
6 6 <% else : %>
7 7 request({
8   - url: "<%= @apiUrl %><%= @url %>",<% if @body: %>
9   - body: <%= @helpers.escape @body %>,<% end %><% if @helpers.isNotEmpty @headers: %>
10   - headers: {<%= ("#{@helpers.escape header}: #{@helpers.escape value}" for header,value of @headers).join(", ") %>}, <% end %>
  8 + url: "<%= @apiUrl %><%= @url %>",
  9 +<% if @body: %>
  10 + body: <%= @helpers.escape @body %>,
  11 +<% end %>
  12 +<% if @helpers.isNotEmpty @headers: %>
  13 + headers: {<%= ("#{@helpers.escape header}: #{@helpers.escape value}" for header,value of @headers).join(", ") %>},
  14 +<% end %>
11 15 method: "<%= @method.toUpperCase() %>"
12 16 }, function (error, response, body) {
13   -<% end %>
  17 +<% end %>
14 18 console.log("Status", response.statusCode);
15 19 console.log("Headers", JSON.stringify(response.headers));
16 20 console.log("Reponse received", body);
2  php.html
@@ -13,7 +13,7 @@
13 13 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "<%= @method %>");
14 14 <% end %>
15 15 <% if @method isnt 'GET' and (@contentType is "text/html" or @contentType is "text/plain"): %>
16   -$fields = <%= eos %><%= "#{line}\n" for line in @body %>EOT;
  16 +$fields = <%= eos %><%= "#{line}\n" for line in @body.split('\n') %>EOT;
17 17 curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
18 18 <% else if @body and @body.length > 0: %>
19 19 curl_setopt($ch, CURLOPT_POSTFIELDS, <%= @helpers.escape @body %>);
30 python.html
... ... @@ -1,16 +1,26 @@
1 1 <section name="python" class="python">
2 2 <p class="ioDesc">Request</p>
3 3 <pre class="incoming"><code class="language-python">from urllib2 import Request, urlopen
4   -<% if @contentType is "application/json": %>from json import dumps
5   -<% else if @contentType is "application/x-www-form-urlencoded": %>from urllib import urlencode
  4 +<% if @contentType is "application/json": %>
  5 +from json import dumps
  6 +<% else if @contentType is "application/x-www-form-urlencoded": %>
  7 +from urllib import urlencode
6 8 <% end %>
7   -<% if @contentType is "application/x-www-form-urlencoded" and @body: %>values = urlencode(<%= @body %>)
8   -<% else if @contentType is "application/json" and @body: %>values = dumps(<%= @body %>)
9   -<% else if @method isnt 'GET' and (@contentType is "text/html" or @contentType is "text/plain") and @body: %>values = <%= @helpers.escape @body %>
10   -<% else if @method isnt 'GET' and @body: %>values = <%= @helpers.escape @body %>
11   -<% end %><% if @helpers.isNotEmpty @headers: %>headers = {<%= ("#{@helpers.escape header}: #{@helpers.escape value}" for header,value of @headers).join(", ") %>}
12   -<% end %>request = Request("<%= @apiUrl %><%= @url %>"<% if @method isnt 'GET' and @body : %>, data=values<% end %><% if @helpers.isNotEmpty @headers: %>, headers=headers<% end %>)
13   -<% if @method not in ['GET', 'POST'] : %>request.get_method = lambda: '<%= @method %>'
14   -<% end %>response_body = urlopen(request).read()
  9 +<% if @contentType is "application/x-www-form-urlencoded" and @body: %>
  10 +values = urlencode(<%= @body %>)
  11 +<% else if @contentType is "application/json" and @body: %>
  12 +values = dumps(<%= @body %>)
  13 +<% else if @method isnt 'GET' and @body: %>
  14 +values = <%= @helpers.escape @body %>
  15 +
  16 +<% end %>
  17 +<% if @helpers.isNotEmpty @headers: %>
  18 +headers = {<%= ("#{@helpers.escape header}: #{@helpers.escape value}" for header,value of @headers).join(", ") %>}
  19 +<% end %>
  20 +request = Request("<%= @apiUrl %><%= @url %>"<% if @method isnt 'GET' and @body : %>, data=values<% end %><% if @helpers.isNotEmpty @headers: %>, headers=headers<% end %>)
  21 +<% if @method not in ['GET', 'POST'] : %>
  22 +request.get_method = lambda: '<%= @method %>'
  23 +<% end %>
  24 +response_body = urlopen(request).read()
15 25 print response_body</code></pre>
16 26 </section>

0 comments on commit ee2752c

Please sign in to comment.
Something went wrong with that request. Please try again.