forked from apiaryio/language-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodejs.html
22 lines (22 loc) · 833 Bytes
/
nodejs.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<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>