Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
23 lines (22 sloc) 833 Bytes
<section name="nodejs" class="nodejs">
<p class="ioDesc">Request</p>
<pre class="incoming"><code class="language-javascript">var request = require("request");
<% if @method is "GET" and not @headers: %>
request("<%= @apiUrl %><%= @url %>", function (error, response, body) {
<% else : %>
request({
url: "<%= @apiUrl %><%= @url %>",
<% if @body: %>
body: <%= @helpers.escape @body %>,
<% end %>
<% if @helpers.isNotEmpty @headers: %>
headers: {<%= ("#{@helpers.escape header}: #{@helpers.escape value}" for header,value of @headers).join(", ") %>},
<% end %>
method: "<%= @method.toUpperCase() %>"
}, function (error, response, body) {
<% end %>
console.log("Status", response.statusCode);
console.log("Headers", JSON.stringify(response.headers));
console.log("Response received", body);
});</code></pre>
</section>