Skip to content
Browse files

improved docs for http client

  • Loading branch information...
1 parent 009d17c commit 47c3f4ba606785845b5c337638d96bc6d8c3957d @purplefox purplefox committed
Showing with 317 additions and 217 deletions.
  1. +29 −25 core_manual_groovy.html
  2. +33 −25 core_manual_groovy.md
  3. +29 −25 core_manual_java.html
  4. +33 −25 core_manual_java.md
  5. +28 −24 core_manual_js.html
  6. +32 −24 core_manual_js.md
  7. +31 −17 core_manual_python.html
  8. +35 −17 core_manual_python.md
  9. +30 −16 core_manual_ruby.html
  10. +37 −19 core_manual_ruby.md
View
54 core_manual_groovy.html
@@ -1041,17 +1041,19 @@ <h4 id="request-method">Request Method</h4><br/>
<p>The request object has a property <code>method</code> which is a string representing what HTTP method was requested. Possible values for <code>method</code> are: <code>GET</code>, <code>PUT</code>, <code>POST</code>, <code>DELETE</code>, <code>HEAD</code>, <code>OPTIONS</code>, <code>CONNECT</code>, <code>TRACE</code>, <code>PATCH</code>.</p>
<h4 id="request-uri">Request URI</h4><br/>
<p>The request object has a property <code>uri</code> which contains the full URI (Uniform Resource Locator) of the request. For example, if the request URI was:</p>
-<pre class="prettyprint">http://localhost:8080/a/b/c/page.html?param1=abc&amp;param2=xyz
+<pre class="prettyprint">/a/b/c/page.html?param1=abc&amp;param2=xyz
</pre>
-<p>Then <code>request.uri</code> would contain the string <code>http://localhost:8080/a/b/c/page.html?param1=abc&amp;param2=xyz</code>.</p>
+<p>Then <code>request.uri</code> would contain the string <code>/a/b/c/page.html?param1=abc&amp;param2=xyz</code>.</p>
+<p>Request URIs can be relative or absolute (with a domain) depending on what the client sent. In many cases they will be relative.</p>
+<p>The request uri contains the value as defined in <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html">Section 5.1.2 of the HTTP specification - Request-URI</a></p>
<h4 id="request-path">Request Path</h4><br/>
<p>The request object has a property <code>path</code> which contains the path of the request. For example, if the request URI was:</p>
-<pre class="prettyprint">http://localhost:8080/a/b/c/page.html?param1=abc&amp;param2=xyz
+<pre class="prettyprint">/a/b/c/page.html?param1=abc&amp;param2=xyz
</pre>
<p>Then <code>request.path</code> would contain the string <code>/a/b/c/page.html</code></p>
<h4 id="request-query">Request Query</h4><br/>
<p>The request object has a property <code>query</code> which contains the query of the request. For example, if the request URI was:</p>
-<pre class="prettyprint">http://localhost:8080/a/b/c/page.html?param1=abc&amp;param2=xyz
+<pre class="prettyprint">/a/b/c/page.html?param1=abc&amp;param2=xyz
</pre>
<p>Then <code>request.query</code> would contain the string <code>param1=abc&amp;param2=xyz</code></p>
<h4 id="request-headers">Request Headers</h4><br/>
@@ -1075,7 +1077,7 @@ <h4 id="request-params">Request params</h4><br/>
<p>Similarly to the headers, the map of request parameters are available using the <code>params</code> property on the request
object.</p>
<p>Request parameters are sent on the request URI, after the path. For example if the URI was:</p>
-<pre class="prettyprint">http://localhost:8080/page.html?param1=abc&amp;param2=xyz
+<pre class="prettyprint">/page.html?param1=abc&amp;param2=xyz
</pre>
<p>Then the params map would contain the following entries:</p>
<pre class="prettyprint">param1: 'abc'
@@ -1232,7 +1234,7 @@ <h3 id="creating-an-http-client">Creating an HTTP Client</h3><br/>
<pre class="prettyprint">HttpClient client = vertx.createHttpClient(port: 8181, host: "foo.com")
</pre>
<p>A single <code>HttpClient</code> always connects to the same host and port. If you want to connect to different servers, create more instances.</p>
-<p>The default value for hostname is <code>localhost</code>, and the default value for port is <code>80</code>.</p>
+<p>The default port is <code>80</code> and the default host is <code>localhost</code>. So if you don't explicitly set these values that's what the client will attempt to connect to.</p>
<h3 id="pooling-and-keep-alive">Pooling and Keep Alive</h3><br/>
<p>By default the <code>HttpClient</code> pools HTTP connections. As you make requests a connection is borrowed from the pool and returned when the HTTP response has ended.</p>
<p>If you do not want connections to be pooled you can call <code>setKeepAlive</code> with <code>false</code>:</p>
@@ -1250,9 +1252,9 @@ <h3 id="closing-the-client">Closing the client</h3><br/>
<h3 id="making-requests">Making Requests</h3><br/>
<p>To make a request using the client you invoke one the methods named after the HTTP method that you want to invoke.</p>
<p>For example, to make a <code>POST</code> request:</p>
-<pre class="prettyprint">def client = vertx.createHttpClient()
+<pre class="prettyprint">def client = vertx.createHttpClient(host: "foo.com")
-def request = client.post("http://localhost:8080/some-path/") { resp -&gt;
+def request = client.post("/some-path/") { resp -&gt;
println "Got a response: ${resp.statusCode}"
}
@@ -1261,21 +1263,23 @@ <h3 id="making-requests">Making Requests</h3><br/>
<p>To make a PUT request use the <code>put</code> method, to make a GET request use the <code>get</code> method, etc.</p>
<p>Legal request methods are: <code>get</code>, <code>put</code>, <code>post</code>, <code>delete</code>, <code>head</code>, <code>options</code>, <code>connect</code>, <code>trace</code> and <code>patch</code>.</p>
<p>The general modus operandi is you invoke the appropriate method passing in the request URI as the first parameter. The second parameter is an event handler which will get called when the corresponding response arrives. The response handler is passed the client response object as an argument.</p>
+<p>The value specified in the request URI corresponds to the Request-URI as specified in <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html">Section 5.1.2 of the HTTP specification</a>. In most cases it will be a relative URI.</p>
+<p><em>Please note that the domain/port that the client connects to is determined by <code>setPort</code> and <code>setHost</code>, and is not parsed from the uri.</em></p>
<p>The return value from the appropriate request method is an instance of <code>org.vertx.groovy.core.http.HTTPClientRequest</code>. You can use this to add headers to the request, and to write to the request body. The request object implements <code>WriteStream</code>.</p>
<p>Once you have finished with the request you must call the <code>end</code> method.</p>
<p>If you don't know the name of the request method in advance there is a general <code>request</code> method which takes the HTTP method as a parameter:</p>
-<pre class="prettyprint">def client = vertx.createHttpClient()
+<pre class="prettyprint">def client = vertx.createHttpClient(host: "foo.com")
-def request = client.request("POST", "http://localhost:8080/some-path/") { resp -&gt;
+def request = client.request("POST", "/some-path/") { resp -&gt;
println "Got a response: ${resp.statusCode}"
}
request.end()
</pre>
<p>There is also a method called <code>getNow</code> which does the same as <code>get</code>, but automatically ends the request. This is useful for simple GETs which don't have a request body:</p>
-<pre class="prettyprint">def client = vertx.createHttpClient()
+<pre class="prettyprint">def client = vertx.createHttpClient(host: "foo.com")
-client.getNow("http://localhost:8080/some-path/") { resp -&gt;
+client.getNow("/some-path/") { resp -&gt;
println "Got a response: ${resp.statusCode}"
}
</pre>
@@ -1317,9 +1321,9 @@ <h4 id="ending-http-requests">Ending HTTP requests</h4><br/>
<p>The method can also be called with a string or Buffer in the same way <code>write</code> is called. In this case it's just the same as calling write with a string or Buffer followed by calling <code>end</code> with no arguments.</p>
<h4 id="writing-request-headers">Writing Request Headers</h4><br/>
<p>To write headers to the request, add them to <code>headers</code> property:</p>
-<pre class="prettyprint">def client = vertx.createHttpClient()
+<pre class="prettyprint">def client = vertx.createHttpClient(host: "foo.com")
-def request = client.post("http://localhost:8080/some-path/") { resp -&gt;
+def request = client.post("/some-path/") { resp -&gt;
println "Got a response: ${resp.statusCode}"
}
@@ -1330,7 +1334,7 @@ <h4 id="writing-request-headers">Writing Request Headers</h4><br/>
<pre class="prettyprint">request.putHeader("Some-Header", "Some-Value").putHeader("Some-Other", "Blah")
</pre>
<p>These can all be chained together as per the common vert.x API pattern:</p>
-<pre class="prettyprint">client.post("http://localhost:8080/some-path/") { resp -&gt;
+<pre class="prettyprint">vertx.createHttpClient(host: "foo.com").post("/some-path/") { resp -&gt;
println "Got a response: ${resp.statusCode}"
}.putHeader("Some-Header", "Some-Value").end()
</pre>
@@ -1344,9 +1348,9 @@ <h3 id="http-client-responses">HTTP Client Responses</h3><br/>
<p>Client responses are received as an argument to the response handler that is passed into one of the request methods on the HTTP client.</p>
<p>The response object implements <code>ReadStream</code>, so it can be pumped to a <code>WriteStream</code> like any other <code>ReadStream</code>.</p>
<p>To query the status code of the response use the <code>statusCode</code> property. The <code>statusMessage</code> property contains the status message. For example:</p>
-<pre class="prettyprint">def client = vertx.createHttpClient()
+<pre class="prettyprint">def client = vertx.createHttpClient(host: "foo.com")
-client.getNow("http://localhost:8080/some-path/") { resp -&gt;
+client.getNow("/some-path/") { resp -&gt;
println "server returned status code: ${resp.statusCode}"
println "server returned status message: ${resp.statusMessage}"
}
@@ -1355,9 +1359,9 @@ <h4 id="reading-data-from-the-response-body">Reading Data from the Response Body
<p>The API for reading a http client response body is very similar to the API for reading a http server request body.</p>
<p>Sometimes an HTTP response contains a body that we want to read. Like an HTTP request, the client response handler is called when all the response headers have arrived, not when the entire response body has arrived.</p>
<p>To receive the response body, you set a <code>dataHandler</code> on the response object which gets called as parts of the HTTP response arrive. Here's an example:</p>
-<pre class="prettyprint">def client = vertx.createHttpClient()
+<pre class="prettyprint">def client = vertx.createHttpClient(host: "foo.com")
-client.getNow("http://localhost:8080/some-path/") { resp -&gt;
+client.getNow("/some-path/") { resp -&gt;
resp.dataHandler { buffer -&gt;
println "I received ${buffer.length} bytes"
}
@@ -1366,9 +1370,9 @@ <h4 id="reading-data-from-the-response-body">Reading Data from the Response Body
<p>The response object implements the <code>ReadStream</code> interface so you can pump the response body to a <code>WriteStream</code>. See the chapter on streams and pump for a detailed explanation.</p>
<p>The <code>dataHandler</code> can be called multiple times for a single HTTP response.</p>
<p>As with a server request, if you wanted to read the entire response body before doing something with it you could do something like the following:</p>
-<pre class="prettyprint">def client = vertx.createHttpClient()
+<pre class="prettyprint">def client = vertx.createHttpClient(host: "foo.com")
-client.getNow("http://localhost:8080/some-path/") { resp -&gt;
+client.getNow("/some-path/") { resp -&gt;
def body = new Buffer()
resp.dataHandler { buffer -&gt;
body &lt;&lt; buffer
@@ -1382,9 +1386,9 @@ <h4 id="reading-data-from-the-response-body">Reading Data from the Response Body
<p>The body handler is called only once when the <em>entire</em> response body has been read.</p>
<p><em>Beware of doing this with very large responses since the entire response body will be stored in memory.</em></p>
<p>Here's an example using <code>bodyHandler</code>:</p>
-<pre class="prettyprint">def client = vertx.createHttpClient()
+<pre class="prettyprint">def client = vertx.createHttpClient(host: "foo.com")
-client.getNow("http://localhost:8080/some-path/") { resp -&gt;
+client.getNow("/some-path/") { resp -&gt;
resp.bodyHandler { body -&gt;
println "The total body received was ${body.length} bytes"
}
@@ -1399,9 +1403,9 @@ <h3 id="100-continue-handling">100-Continue Handling</h3><br/>
<p>Vert.x allows you to set a <code>continueHandler</code> on the client request object. This will be called if the server sends back a <code>Status: 100 (Continue)</code> response to signify it is ok to send the rest of the request.</p>
<p>This is used in conjunction with the <code>sendHead</code> method to send the head of the request.</p>
<p>An example will illustrate this:</p>
-<pre class="prettyprint">def client = vertx.createHttpClient()
+<pre class="prettyprint">def client = vertx.createHttpClient(host: "foo.com")
-def request = client.put("http://localhost:8080/some-path/") { resp -&gt;
+def request = client.put("/some-path/") { resp -&gt;
println "Got a response ${resp.statusCode}"
}
View
58 core_manual_groovy.md
@@ -1069,15 +1069,19 @@ The request object has a property `method` which is a string representing what H
The request object has a property `uri` which contains the full URI (Uniform Resource Locator) of the request. For example, if the request URI was:
- http://localhost:8080/a/b/c/page.html?param1=abc&param2=xyz
+ /a/b/c/page.html?param1=abc&param2=xyz
+
+Then `request.uri` would contain the string `/a/b/c/page.html?param1=abc&param2=xyz`.
+
+Request URIs can be relative or absolute (with a domain) depending on what the client sent. In many cases they will be relative.
-Then `request.uri` would contain the string `http://localhost:8080/a/b/c/page.html?param1=abc&param2=xyz`.
+The request uri contains the value as defined in [Section 5.1.2 of the HTTP specification - Request-URI](http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html)
#### Request Path
The request object has a property `path` which contains the path of the request. For example, if the request URI was:
- http://localhost:8080/a/b/c/page.html?param1=abc&param2=xyz
+ /a/b/c/page.html?param1=abc&param2=xyz
Then `request.path` would contain the string `/a/b/c/page.html`
@@ -1085,7 +1089,7 @@ Then `request.path` would contain the string `/a/b/c/page.html`
The request object has a property `query` which contains the query of the request. For example, if the request URI was:
- http://localhost:8080/a/b/c/page.html?param1=abc&param2=xyz
+ /a/b/c/page.html?param1=abc&param2=xyz
Then `request.query` would contain the string `param1=abc&param2=xyz`
@@ -1118,7 +1122,7 @@ object.
Request parameters are sent on the request URI, after the path. For example if the URI was:
- http://localhost:8080/page.html?param1=abc&param2=xyz
+ /page.html?param1=abc&param2=xyz
Then the params map would contain the following entries:
@@ -1342,7 +1346,7 @@ You set the port and hostname (or ip address) that the client will connect to us
A single `HttpClient` always connects to the same host and port. If you want to connect to different servers, create more instances.
-The default value for hostname is `localhost`, and the default value for port is `80`.
+The default port is `80` and the default host is `localhost`. So if you don't explicitly set these values that's what the client will attempt to connect to.
### Pooling and Keep Alive
@@ -1372,9 +1376,9 @@ To make a request using the client you invoke one the methods named after the HT
For example, to make a `POST` request:
- def client = vertx.createHttpClient()
+ def client = vertx.createHttpClient(host: "foo.com")
- def request = client.post("http://localhost:8080/some-path/") { resp ->
+ def request = client.post("/some-path/") { resp ->
println "Got a response: ${resp.statusCode}"
}
@@ -1386,15 +1390,19 @@ Legal request methods are: `get`, `put`, `post`, `delete`, `head`, `options`, `c
The general modus operandi is you invoke the appropriate method passing in the request URI as the first parameter. The second parameter is an event handler which will get called when the corresponding response arrives. The response handler is passed the client response object as an argument.
+The value specified in the request URI corresponds to the Request-URI as specified in [Section 5.1.2 of the HTTP specification](http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html). In most cases it will be a relative URI.
+
+*Please note that the domain/port that the client connects to is determined by `setPort` and `setHost`, and is not parsed from the uri.*
+
The return value from the appropriate request method is an instance of `org.vertx.groovy.core.http.HTTPClientRequest`. You can use this to add headers to the request, and to write to the request body. The request object implements `WriteStream`.
Once you have finished with the request you must call the `end` method.
If you don't know the name of the request method in advance there is a general `request` method which takes the HTTP method as a parameter:
- def client = vertx.createHttpClient()
+ def client = vertx.createHttpClient(host: "foo.com")
- def request = client.request("POST", "http://localhost:8080/some-path/") { resp ->
+ def request = client.request("POST", "/some-path/") { resp ->
println "Got a response: ${resp.statusCode}"
}
@@ -1402,9 +1410,9 @@ If you don't know the name of the request method in advance there is a general `
There is also a method called `getNow` which does the same as `get`, but automatically ends the request. This is useful for simple GETs which don't have a request body:
- def client = vertx.createHttpClient()
+ def client = vertx.createHttpClient(host: "foo.com")
- client.getNow("http://localhost:8080/some-path/") { resp ->
+ client.getNow("/some-path/") { resp ->
println "Got a response: ${resp.statusCode}"
}
@@ -1466,9 +1474,9 @@ The method can also be called with a string or Buffer in the same way `write` is
To write headers to the request, add them to `headers` property:
- def client = vertx.createHttpClient()
+ def client = vertx.createHttpClient(host: "foo.com")
- def request = client.post("http://localhost:8080/some-path/") { resp ->
+ def request = client.post("/some-path/") { resp ->
println "Got a response: ${resp.statusCode}"
}
@@ -1481,7 +1489,7 @@ You can also add them using the `putHeader` method. This enables a more fluent A
These can all be chained together as per the common vert.x API pattern:
- client.post("http://localhost:8080/some-path/") { resp ->
+ vertx.createHttpClient(host: "foo.com").post("/some-path/") { resp ->
println "Got a response: ${resp.statusCode}"
}.putHeader("Some-Header", "Some-Value").end()
@@ -1503,9 +1511,9 @@ The response object implements `ReadStream`, so it can be pumped to a `WriteStre
To query the status code of the response use the `statusCode` property. The `statusMessage` property contains the status message. For example:
- def client = vertx.createHttpClient()
+ def client = vertx.createHttpClient(host: "foo.com")
- client.getNow("http://localhost:8080/some-path/") { resp ->
+ client.getNow("/some-path/") { resp ->
println "server returned status code: ${resp.statusCode}"
println "server returned status message: ${resp.statusMessage}"
}
@@ -1519,9 +1527,9 @@ Sometimes an HTTP response contains a body that we want to read. Like an HTTP re
To receive the response body, you set a `dataHandler` on the response object which gets called as parts of the HTTP response arrive. Here's an example:
- def client = vertx.createHttpClient()
+ def client = vertx.createHttpClient(host: "foo.com")
- client.getNow("http://localhost:8080/some-path/") { resp ->
+ client.getNow("/some-path/") { resp ->
resp.dataHandler { buffer ->
println "I received ${buffer.length} bytes"
}
@@ -1534,9 +1542,9 @@ The `dataHandler` can be called multiple times for a single HTTP response.
As with a server request, if you wanted to read the entire response body before doing something with it you could do something like the following:
- def client = vertx.createHttpClient()
+ def client = vertx.createHttpClient(host: "foo.com")
- client.getNow("http://localhost:8080/some-path/") { resp ->
+ client.getNow("/some-path/") { resp ->
def body = new Buffer()
resp.dataHandler { buffer ->
body << buffer
@@ -1556,9 +1564,9 @@ The body handler is called only once when the *entire* response body has been re
Here's an example using `bodyHandler`:
- def client = vertx.createHttpClient()
+ def client = vertx.createHttpClient(host: "foo.com")
- client.getNow("http://localhost:8080/some-path/") { resp ->
+ client.getNow("/some-path/") { resp ->
resp.bodyHandler { body ->
println "The total body received was ${body.length} bytes"
}
@@ -1582,9 +1590,9 @@ This is used in conjunction with the `sendHead` method to send the head of the r
An example will illustrate this:
- def client = vertx.createHttpClient()
+ def client = vertx.createHttpClient(host: "foo.com")
- def request = client.put("http://localhost:8080/some-path/") { resp ->
+ def request = client.put("/some-path/") { resp ->
println "Got a response ${resp.statusCode}"
}
View
54 core_manual_java.html
@@ -1221,17 +1221,19 @@ <h4 id="request-method">Request Method</h4><br/>
<p>The request object has a property <code>method</code> which is a string representing what HTTP method was requested. Possible values for <code>method</code> are: <code>GET</code>, <code>PUT</code>, <code>POST</code>, <code>DELETE</code>, <code>HEAD</code>, <code>OPTIONS</code>, <code>CONNECT</code>, <code>TRACE</code>, <code>PATCH</code>.</p>
<h4 id="request-uri">Request URI</h4><br/>
<p>The request object has a property <code>uri</code> which contains the full URI (Uniform Resource Locator) of the request. For example, if the request URI was:</p>
-<pre class="prettyprint">http://localhost:8080/a/b/c/page.html?param1=abc&amp;param2=xyz
+<pre class="prettyprint">/a/b/c/page.html?param1=abc&amp;param2=xyz
</pre>
-<p>Then <code>request.uri</code> would contain the string <code>http://localhost:8080/a/b/c/page.html?param1=abc&amp;param2=xyz</code>.</p>
+<p>Then <code>request.uri</code> would contain the string <code>/a/b/c/page.html?param1=abc&amp;param2=xyz</code>.</p>
+<p>Request URIs can be relative or absolute (with a domain) depending on what the client sent. In many cases they will be relative.</p>
+<p>The request uri contains the value as defined in <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html">Section 5.1.2 of the HTTP specification - Request-URI</a></p>
<h4 id="request-path">Request Path</h4><br/>
<p>The request object has a property <code>path</code> which contains the path of the request. For example, if the request URI was:</p>
-<pre class="prettyprint">http://localhost:8080/a/b/c/page.html?param1=abc&amp;param2=xyz
+<pre class="prettyprint">a/b/c/page.html?param1=abc&amp;param2=xyz
</pre>
<p>Then <code>request.path</code> would contain the string <code>/a/b/c/page.html</code></p>
<h4 id="request-query">Request Query</h4><br/>
<p>The request object has a property <code>query</code> which contains the query of the request. For example, if the request URI was:</p>
-<pre class="prettyprint">http://localhost:8080/a/b/c/page.html?param1=abc&amp;param2=xyz
+<pre class="prettyprint">a/b/c/page.html?param1=abc&amp;param2=xyz
</pre>
<p>Then <code>request.query</code> would contain the string <code>param1=abc&amp;param2=xyz</code> <br/>
</p>
@@ -1256,7 +1258,7 @@ <h4 id="request-params">Request params</h4><br/>
<p>Similarly to the headers, the map of request parameters are available using the <code>params()</code> method on the request object. <br/>
</p>
<p>Request parameters are sent on the request URI, after the path. For example if the URI was:</p>
-<pre class="prettyprint">http://localhost:8080/page.html?param1=abc&amp;param2=xyz
+<pre class="prettyprint">/page.html?param1=abc&amp;param2=xyz
</pre>
<p>Then the params map would contain the following entries:</p>
<pre class="prettyprint">param1: 'abc'
@@ -1461,7 +1463,7 @@ <h3 id="creating-an-http-client">Creating an HTTP Client</h3><br/>
.setHost("foo.com");
</pre>
<p>A single <code>HTTPClient</code> always connects to the same host and port. If you want to connect to different servers, create more instances.</p>
-<p>The default value for hostname is <code>localhost</code>, and the default value for port is <code>80</code>.<br/>
+<p>The default port is <code>80</code> and the default host is <code>localhost</code>. So if you don't explicitly set these values that's what the client will attempt to connect to. <br/>
</p>
<h3 id="pooling-and-keep-alive">Pooling and Keep Alive</h3><br/>
<p>By default the <code>HTTPClient</code> pools HTTP connections. As you make requests a connection is borrowed from the pool and returned when the HTTP response has ended.</p>
@@ -1487,9 +1489,9 @@ <h3 id="closing-the-client">Closing the client</h3><br/>
<h3 id="making-requests">Making Requests</h3><br/>
<p>To make a request using the client you invoke one the methods named after the HTTP method that you want to invoke.</p>
<p>For example, to make a <code>POST</code> request:</p>
-<pre class="prettyprint">HttpClient client = vertx.createHttpClient();
+<pre class="prettyprint">HttpClient client = vertx.createHttpClient().setHost("foo.com");
-HttpClientRequest request = client.post("http://localhost:8080/some-path/", new Handler&lt;HttpClientResponse&gt;() {
+HttpClientRequest request = client.post("/some-path/", new Handler&lt;HttpClientResponse&gt;() {
public void handle(HttpClientResponse resp) {
log.info("Got a response: " + resp.statusCode());
}
@@ -1500,12 +1502,14 @@ <h3 id="making-requests">Making Requests</h3><br/>
<p>To make a PUT request use the <code>put</code> method, to make a GET request use the <code>get</code> method, etc.</p>
<p>Legal request methods are: <code>get</code>, <code>put</code>, <code>post</code>, <code>delete</code>, <code>head</code>, <code>options</code>, <code>connect</code>, <code>trace</code> and <code>patch</code>.</p>
<p>The general modus operandi is you invoke the appropriate method passing in the request URI as the first parameter, the second parameter is an event handler which will get called when the corresponding response arrives. The response handler is passed the client response object as an argument.</p>
+<p>The value specified in the request URI corresponds to the Request-URI as specified in <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html">Section 5.1.2 of the HTTP specification</a>. In most cases it will be a relative URI.</p>
+<p><em>Please note that the domain/port that the client connects to is determined by <code>setPort</code> and <code>setHost</code>, and is not parsed from the uri.</em></p>
<p>The return value from the appropriate request method is an instance of <code>org.vertx.java.core.http.HTTPClientRequest</code>. You can use this to add headers to the request, and to write to the request body. The request object implements <code>WriteStream</code>.</p>
<p>Once you have finished with the request you must call the <code>end</code> function.</p>
<p>If you don't know the name of the request method in advance there is a general <code>request</code> method which takes the HTTP method as a parameter:</p>
-<pre class="prettyprint">HttpClient client = vertx.createHttpClient();
+<pre class="prettyprint">HttpClient client = vertx.createHttpClient().setHost("foo.com");
-HttpClientRequest request = client.request("POST", "http://localhost:8080/some-path/",
+HttpClientRequest request = client.request("POST", "/some-path/",
new Handler&lt;HttpClientResponse&gt;() {
public void handle(HttpClientResponse resp) {
log.info("Got a response: " + resp.statusCode());
@@ -1515,9 +1519,9 @@ <h3 id="making-requests">Making Requests</h3><br/>
request.end();
</pre>
<p>There is also a method called <code>getNow</code> which does the same as <code>get</code>, but automatically ends the request. This is useful for simple GETs which don't have a request body:</p>
-<pre class="prettyprint">HttpClient client = vertx.createHttpClient();
+<pre class="prettyprint">HttpClient client = vertx.createHttpClient().setHost("foo.com");
-client.getNow("http://localhost:8080/some-path/", new Handler&lt;HttpClientResponse&gt;() {
+client.getNow("/some-path/", new Handler&lt;HttpClientResponse&gt;() {
public void handle(HttpClientResponse resp) {
log.info("Got a response: " + resp.statusCode());
}
@@ -1559,9 +1563,9 @@ <h4 id="ending-http-requests">Ending HTTP requests</h4><br/>
<p>The function can also be called with a string or Buffer in the same way <code>write</code> is called. In this case it's just the same as calling write with a string or Buffer followed by calling <code>end</code> with no arguments.</p>
<h4 id="writing-request-headers">Writing Request Headers</h4><br/>
<p>To write headers to the request, add them to the map returned from the <code>headers()</code> method:</p>
-<pre class="prettyprint">HttpClient client = vertx.createHttpClient();
+<pre class="prettyprint">HttpClient client = vertx.createHttpClient().setHost("foo.com");
-HttpClientRequest request = client.post("http://localhost:8080/some-path/", new Handler&lt;HttpClientResponse&gt;() {
+HttpClientRequest request = client.post("/some-path/", new Handler&lt;HttpClientResponse&gt;() {
public void handle(HttpClientResponse resp) {
log.info("Got a response: " + resp.statusCode());
}
@@ -1574,7 +1578,7 @@ <h4 id="writing-request-headers">Writing Request Headers</h4><br/>
<pre class="prettyprint">request.putHeader("Some-Header", "Some-Value").putHeader("Some-Other", "Blah");
</pre>
<p>These can all be chained together as per the common vert.x API pattern:</p>
-<pre class="prettyprint">client.post("http://localhost:8080/some-path/", new Handler&lt;HttpClientResponse&gt;() {
+<pre class="prettyprint">client.setHost("foo.com").post("/some-path/", new Handler&lt;HttpClientResponse&gt;() {
public void handle(HttpClientResponse resp) {
log.info("Got a response: " + resp.statusCode());
}
@@ -1591,9 +1595,9 @@ <h3 id="http-client-responses">HTTP Client Responses</h3><br/>
<p>Client responses are received as an argument to the response handler that is passed into one of the request methods on the HTTP client.</p>
<p>The response object implements <code>ReadStream</code>, so it can be pumped to a <code>WriteStream</code> like any other <code>ReadStream</code>.</p>
<p>To query the status code of the response use the <code>statusCode</code> property. The <code>statusMessage</code> property contains the status message. For example:</p>
-<pre class="prettyprint">HttpClient client = vertx.createHttpClient();
+<pre class="prettyprint">HttpClient client = vertx.createHttpClient().setHost("foo.com");
-client.getNow("http://localhost:8080/some-path/", new Handler&lt;HttpClientResponse&gt;() {
+client.getNow("/some-path/", new Handler&lt;HttpClientResponse&gt;() {
public void handle(HttpClientResponse resp) {
log.info('server returned status code: ' + resp.statusCode);
log.info('server returned status message: ' + resp.statusMessage);
@@ -1604,9 +1608,9 @@ <h4 id="reading-data-from-the-response-body">Reading Data from the Response Body
<p>The API for reading an HTTP client response body is very similar to the API for reading a HTTP server request body.</p>
<p>Sometimes an HTTP response contains a body that we want to read. Like an HTTP request, the client response handler is called when all the response headers have arrived, not when the entire response body has arrived.</p>
<p>To receive the response body, you set a <code>dataHandler</code> on the response object which gets called as parts of the HTTP response arrive. Here's an example:</p>
-<pre class="prettyprint">HttpClient client = vertx.createHttpClient();
+<pre class="prettyprint">HttpClient client = vertx.createHttpClient().setHost("foo.com");
-client.getNow("http://localhost:8080/some-path/", new Handler&lt;HttpClientResponse&gt;() {
+client.getNow("/some-path/", new Handler&lt;HttpClientResponse&gt;() {
public void handle(HttpClientResponse resp) {
resp.dataHandler(new Handler&lt;Buffer&gt;() {
public void handle(Buffer data) {
@@ -1619,9 +1623,9 @@ <h4 id="reading-data-from-the-response-body">Reading Data from the Response Body
<p>The response object implements the <code>ReadStream</code> interface so you can pump the response body to a <code>WriteStream</code>. See the chapter on streams and pump for a detailed explanation. </p>
<p>The <code>dataHandler</code> can be called multiple times for a single HTTP response.</p>
<p>As with a server request, if you wanted to read the entire response body before doing something with it you could do something like the following:</p>
-<pre class="prettyprint">HttpClient client = vertx.createHttpClient();
+<pre class="prettyprint">HttpClient client = vertx.createHttpClient().setHost("foo.com");
-client.getNow("http://localhost:8080/some-path/", new Handler&lt;HttpClientResponse&gt;() {
+client.getNow("/some-path/", new Handler&lt;HttpClientResponse&gt;() {
public void handle(HttpClientResponse resp) {
final Buffer body = new Buffer(0);
@@ -1646,9 +1650,9 @@ <h4 id="reading-data-from-the-response-body">Reading Data from the Response Body
<p>The body handler is called only once when the <em>entire</em> response body has been read.</p>
<p><em>Beware of doing this with very large responses since the entire response body will be stored in memory.</em></p>
<p>Here's an example using <code>bodyHandler</code>:</p>
-<pre class="prettyprint">HttpClient client = vertx.createHttpClient();
+<pre class="prettyprint">HttpClient client = vertx.createHttpClient().setHost("foo.com");
-client.getNow("http://localhost:8080/some-path/", new Handler&lt;HttpClientResponse&gt;() {
+client.getNow("/some-path/", new Handler&lt;HttpClientResponse&gt;() {
public void handle(HttpClientResponse resp) {
resp.bodyHandler(new Handler&lt;Buffer&gt;() {
public void handle(Buffer body) {
@@ -1668,9 +1672,9 @@ <h3 id="100-continue-handling">100-Continue Handling</h3><br/>
<p>Vert.x allows you to set a <code>continueHandler</code> on the client request object. This will be called if the server sends back a <code>Status: 100 (Continue)</code> response to signify it is ok to send the rest of the request.</p>
<p>This is used in conjunction with the <code>sendHead</code> function to send the head of the request.</p>
<p>An example will illustrate this:</p>
-<pre class="prettyprint">HttpClient client = vertx.createHttpClient();
+<pre class="prettyprint">HttpClient client = vertx.createHttpClient().setHost("foo.com");
-final HttpClientRequest request = client.put("http://localhost:8080/some-path/", new Handler&lt;HttpClientResponse&gt;() {
+final HttpClientRequest request = client.put("/some-path/", new Handler&lt;HttpClientResponse&gt;() {
public void handle(HttpClientResponse resp) {
log.info("Got a response " + resp.statusCode);
}
View
58 core_manual_java.md
@@ -1242,15 +1242,19 @@ The request object has a property `method` which is a string representing what H
The request object has a property `uri` which contains the full URI (Uniform Resource Locator) of the request. For example, if the request URI was:
- http://localhost:8080/a/b/c/page.html?param1=abc&param2=xyz
+ /a/b/c/page.html?param1=abc&param2=xyz
-Then `request.uri` would contain the string `http://localhost:8080/a/b/c/page.html?param1=abc&param2=xyz`.
+Then `request.uri` would contain the string `/a/b/c/page.html?param1=abc&param2=xyz`.
+
+Request URIs can be relative or absolute (with a domain) depending on what the client sent. In many cases they will be relative.
+
+The request uri contains the value as defined in [Section 5.1.2 of the HTTP specification - Request-URI](http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html)
#### Request Path
The request object has a property `path` which contains the path of the request. For example, if the request URI was:
- http://localhost:8080/a/b/c/page.html?param1=abc&param2=xyz
+ a/b/c/page.html?param1=abc&param2=xyz
Then `request.path` would contain the string `/a/b/c/page.html`
@@ -1258,7 +1262,7 @@ Then `request.path` would contain the string `/a/b/c/page.html`
The request object has a property `query` which contains the query of the request. For example, if the request URI was:
- http://localhost:8080/a/b/c/page.html?param1=abc&param2=xyz
+ a/b/c/page.html?param1=abc&param2=xyz
Then `request.query` would contain the string `param1=abc&param2=xyz`
@@ -1290,7 +1294,7 @@ Similarly to the headers, the map of request parameters are available using the
Request parameters are sent on the request URI, after the path. For example if the URI was:
- http://localhost:8080/page.html?param1=abc&param2=xyz
+ /page.html?param1=abc&param2=xyz
Then the params map would contain the following entries:
@@ -1555,7 +1559,7 @@ This, of course, can be chained:
A single `HTTPClient` always connects to the same host and port. If you want to connect to different servers, create more instances.
-The default value for hostname is `localhost`, and the default value for port is `80`.
+The default port is `80` and the default host is `localhost`. So if you don't explicitly set these values that's what the client will attempt to connect to.
### Pooling and Keep Alive
@@ -1591,9 +1595,9 @@ To make a request using the client you invoke one the methods named after the HT
For example, to make a `POST` request:
- HttpClient client = vertx.createHttpClient();
+ HttpClient client = vertx.createHttpClient().setHost("foo.com");
- HttpClientRequest request = client.post("http://localhost:8080/some-path/", new Handler<HttpClientResponse>() {
+ HttpClientRequest request = client.post("/some-path/", new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
log.info("Got a response: " + resp.statusCode());
}
@@ -1607,15 +1611,19 @@ Legal request methods are: `get`, `put`, `post`, `delete`, `head`, `options`, `c
The general modus operandi is you invoke the appropriate method passing in the request URI as the first parameter, the second parameter is an event handler which will get called when the corresponding response arrives. The response handler is passed the client response object as an argument.
+The value specified in the request URI corresponds to the Request-URI as specified in [Section 5.1.2 of the HTTP specification](http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html). In most cases it will be a relative URI.
+
+*Please note that the domain/port that the client connects to is determined by `setPort` and `setHost`, and is not parsed from the uri.*
+
The return value from the appropriate request method is an instance of `org.vertx.java.core.http.HTTPClientRequest`. You can use this to add headers to the request, and to write to the request body. The request object implements `WriteStream`.
Once you have finished with the request you must call the `end` function.
If you don't know the name of the request method in advance there is a general `request` method which takes the HTTP method as a parameter:
- HttpClient client = vertx.createHttpClient();
+ HttpClient client = vertx.createHttpClient().setHost("foo.com");
- HttpClientRequest request = client.request("POST", "http://localhost:8080/some-path/",
+ HttpClientRequest request = client.request("POST", "/some-path/",
new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
log.info("Got a response: " + resp.statusCode());
@@ -1626,9 +1634,9 @@ If you don't know the name of the request method in advance there is a general `
There is also a method called `getNow` which does the same as `get`, but automatically ends the request. This is useful for simple GETs which don't have a request body:
- HttpClient client = vertx.createHttpClient();
+ HttpClient client = vertx.createHttpClient().setHost("foo.com");
- client.getNow("http://localhost:8080/some-path/", new Handler<HttpClientResponse>() {
+ client.getNow("/some-path/", new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
log.info("Got a response: " + resp.statusCode());
}
@@ -1688,9 +1696,9 @@ The function can also be called with a string or Buffer in the same way `write`
To write headers to the request, add them to the map returned from the `headers()` method:
- HttpClient client = vertx.createHttpClient();
+ HttpClient client = vertx.createHttpClient().setHost("foo.com");
- HttpClientRequest request = client.post("http://localhost:8080/some-path/", new Handler<HttpClientResponse>() {
+ HttpClientRequest request = client.post("/some-path/", new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
log.info("Got a response: " + resp.statusCode());
}
@@ -1705,7 +1713,7 @@ You can also adds them using the `putHeader` method. This enables a more fluent
These can all be chained together as per the common vert.x API pattern:
- client.post("http://localhost:8080/some-path/", new Handler<HttpClientResponse>() {
+ client.setHost("foo.com").post("/some-path/", new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
log.info("Got a response: " + resp.statusCode());
}
@@ -1729,9 +1737,9 @@ The response object implements `ReadStream`, so it can be pumped to a `WriteStre
To query the status code of the response use the `statusCode` property. The `statusMessage` property contains the status message. For example:
- HttpClient client = vertx.createHttpClient();
+ HttpClient client = vertx.createHttpClient().setHost("foo.com");
- client.getNow("http://localhost:8080/some-path/", new Handler<HttpClientResponse>() {
+ client.getNow("/some-path/", new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
log.info('server returned status code: ' + resp.statusCode);
log.info('server returned status message: ' + resp.statusMessage);
@@ -1747,9 +1755,9 @@ Sometimes an HTTP response contains a body that we want to read. Like an HTTP re
To receive the response body, you set a `dataHandler` on the response object which gets called as parts of the HTTP response arrive. Here's an example:
- HttpClient client = vertx.createHttpClient();
+ HttpClient client = vertx.createHttpClient().setHost("foo.com");
- client.getNow("http://localhost:8080/some-path/", new Handler<HttpClientResponse>() {
+ client.getNow("/some-path/", new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
resp.dataHandler(new Handler<Buffer>() {
public void handle(Buffer data) {
@@ -1766,9 +1774,9 @@ The `dataHandler` can be called multiple times for a single HTTP response.
As with a server request, if you wanted to read the entire response body before doing something with it you could do something like the following:
- HttpClient client = vertx.createHttpClient();
+ HttpClient client = vertx.createHttpClient().setHost("foo.com");
- client.getNow("http://localhost:8080/some-path/", new Handler<HttpClientResponse>() {
+ client.getNow("/some-path/", new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
final Buffer body = new Buffer(0);
@@ -1799,9 +1807,9 @@ The body handler is called only once when the *entire* response body has been re
Here's an example using `bodyHandler`:
- HttpClient client = vertx.createHttpClient();
+ HttpClient client = vertx.createHttpClient().setHost("foo.com");
- client.getNow("http://localhost:8080/some-path/", new Handler<HttpClientResponse>() {
+ client.getNow("/some-path/", new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
resp.bodyHandler(new Handler<Buffer>() {
public void handle(Buffer body) {
@@ -1830,9 +1838,9 @@ This is used in conjunction with the `sendHead` function to send the head of the
An example will illustrate this:
- HttpClient client = vertx.createHttpClient();
+ HttpClient client = vertx.createHttpClient().setHost("foo.com");
- final HttpClientRequest request = client.put("http://localhost:8080/some-path/", new Handler<HttpClientResponse>() {
+ final HttpClientRequest request = client.put("/some-path/", new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
log.info("Got a response " + resp.statusCode);
}
View
52 core_manual_js.html
@@ -1161,17 +1161,19 @@ <h4 id="request-method">Request Method</h4><br/>
<p>The request object has a property <code>method</code> which is a string representing what HTTP method was requested. Possible values for <code>method</code> are: <code>GET</code>, <code>PUT</code>, <code>POST</code>, <code>DELETE</code>, <code>HEAD</code>, <code>OPTIONS</code>, <code>CONNECT</code>, <code>TRACE</code>, <code>PATCH</code>.</p>
<h4 id="request-uri">Request URI</h4><br/>
<p>The request object has a property <code>uri</code> which contains the full URI (Uniform Resource Locator) of the request. For example, if the request URI was:</p>
-<pre class="prettyprint">http://localhost:8080/a/b/c/page.html?param1=abc&amp;param2=xyz
+<pre class="prettyprint">/a/b/c/page.html?param1=abc&amp;param2=xyz
</pre>
-<p>Then <code>request.uri</code> would contain the string <code>http://localhost:8080/a/b/c/page.html?param1=abc&amp;param2=xyz</code>.</p>
+<p>Then <code>request.uri</code> would contain the string <code>/a/b/c/page.html?param1=abc&amp;param2=xyz</code>.</p>
+<p>Request URIs can be relative or absolute (with a domain) depending on what the client sent. In many cases they will be relative.</p>
+<p>The request uri contains the value as defined in <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html">Section 5.1.2 of the HTTP specification - Request-URI</a></p>
<h4 id="request-path">Request Path</h4><br/>
<p>The request object has a property <code>path</code> which contains the path of the request. For example, if the request URI was:</p>
-<pre class="prettyprint">http://localhost:8080/a/b/c/page.html?param1=abc&amp;param2=xyz
+<pre class="prettyprint">/a/b/c/page.html?param1=abc&amp;param2=xyz
</pre>
<p>Then <code>request.path</code> would contain the string <code>/a/b/c/page.html</code></p>
<h4 id="request-query">Request Query</h4><br/>
<p>The request object has a property <code>query</code> which contains the query of the request. For example, if the request URI was:</p>
-<pre class="prettyprint">http://localhost:8080/a/b/c/page.html?param1=abc&amp;param2=xyz
+<pre class="prettyprint">/a/b/c/page.html?param1=abc&amp;param2=xyz
</pre>
<p>Then <code>request.query</code> would contain the string <code>param1=abc&amp;param2=xyz</code> <br/>
</p>
@@ -1195,7 +1197,7 @@ <h4 id="request-headers">Request Headers</h4><br/>
<h4 id="request-params">Request params</h4><br/>
<p>Similarly to the headers, the request parameters are available as the <code>params()</code> function on the request object. Again, this is just a JavaScript object (associative array).</p>
<p>Request parameters are sent on the request URI, after the path. For example if the URI was:</p>
-<pre class="prettyprint">http://localhost:8080/page.html?param1=abc&amp;param2=xyz
+<pre class="prettyprint">/page.html?param1=abc&amp;param2=xyz
</pre>
<p>Then the params hash would be the following JS object:</p>
<pre class="prettyprint">{ param1: 'abc', param2: 'xyz' }
@@ -1388,7 +1390,7 @@ <h3 id="creating-an-http-client">Creating an HTTP Client</h3><br/>
.setHost('foo.com');
</pre>
<p>A single <code>HTTPClient</code> always connects to the same host and port. If you want to connect to different servers, create more instances.</p>
-<p>The default value for hostname is <code>localhost</code>, and the default value for port is <code>80</code>.<br/>
+<p>The default port is <code>80</code> and the default host is <code>localhost</code>. So if you don't explicitly set these values that's what the client will attempt to connect to.<br/>
</p>
<h3 id="pooling-and-keep-alive">Pooling and Keep Alive</h3><br/>
<p>By default the <code>HTTPClient</code> pools HTTP connections. As you make requests a connection is borrowed from the pool and returned when the HTTP response has ended.</p>
@@ -1425,21 +1427,23 @@ <h3 id="making-requests">Making Requests</h3><br/>
<p>To make a PUT request use the <code>put</code> method, to make a GET request use the <code>get</code> method, etc.</p>
<p>Legal request methods are: <code>get</code>, <code>put</code>, <code>post</code>, <code>delete</code>, <code>head</code>, <code>options</code>, <code>connect</code>, <code>trace</code> and <code>patch</code>.</p>
<p>The general modus operandi is you invoke the appropriate method passing in the request URI as the first parameter, the second parameter is an event handler which will get called when the corresponding response arrives. The response handler is passed the client response object as an argument.</p>
+<p>The value specified in the request URI corresponds to the Request-URI as specified in <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html">Section 5.1.2 of the HTTP specification</a>. In most cases it will be a relative URI.</p>
+<p><em>Please note that the domain/port that the client connects to is determined by <code>setPort</code> and <code>setHost</code>, and is not parsed from the uri.</em></p>
<p>The return value from the appropriate request method is an <code>HTTPClientRequest</code> object. You can use this to add headers to the request, and to write to the request body. The request object implements <code>WriteStream</code>.</p>
<p>Once you have finished with the request you must call the <code>end</code> function.</p>
<p>If you don't know the name of the request method in advance there is a general <code>request</code> method which takes the HTTP method as a parameter:</p>
-<pre class="prettyprint">var client = vertx.createHttpClient();
+<pre class="prettyprint">var client = vertx.createHttpClient().setHost('foo.com');
-var request = client.request('POST', 'http://localhost:8080/some-path', function(resp) {
+var request = client.request('POST', '/some-path', function(resp) {
log.info('Got a response, status code: ' + resp.statusCode);
});
request.end();
</pre>
<p>There is also a method called <code>getNow</code> which does the same as <code>get</code>, but automatically ends the request. This is useful for simple GETs which don't have a request body:</p>
-<pre class="prettyprint">var client = vertx.createHttpClient();
+<pre class="prettyprint">var client = vertx.createHttpClient().setHost('foo.com');
-client.getNow('http://localhost:8080/some-path', function(resp) {
+client.getNow('/some-path', function(resp) {
log.info('Got a response, status code: ' + resp.statusCode);
});
</pre>
@@ -1477,9 +1481,9 @@ <h4 id="ending-http-requests">Ending HTTP requests</h4><br/>
<p>The function can also be called with a string or Buffer in the same way <code>write</code> is called. In this case it's just the same as calling write with a string or Buffer followed by calling <code>end</code> with no arguments.</p>
<h4 id="writing-request-headers">Writing Request Headers</h4><br/>
<p>To write headers to the request you can just add them to the headers hash:</p>
-<pre class="prettyprint">var client = vertx.createHttpClient();
+<pre class="prettyprint">var client = vertx.createHttpClient().setHost('foo.com');
-var request = client.post('http://localhost:8080/some-path', function(resp) {
+var request = client.post('/some-path', function(resp) {
log.info('Got a response, status code: ' + resp.statusCode);
});
@@ -1488,14 +1492,14 @@ <h4 id="writing-request-headers">Writing Request Headers</h4><br/>
</pre>
<p>Or you can use the <code>putHeader</code> method if you prefer a more fluent API: <br/>
</p>
-<pre class="prettyprint">client.post('http://localhost:8080/some-uri', function(resp) {
+<pre class="prettyprint">client.post('/some-uri', function(resp) {
log.info('Got a response, status code: ' + resp.statusCode);
}).putHeader('Some-Header', 'Some-Value')
.putHeader('Some-Other-Header', 'Some-Other-Value')
.end();
</pre>
<p>If you want to put more than one header at the same time, you can instead use the <code>putAllHeaders</code> function.</p>
-<pre class="prettyprint">client.post('http://localhost:8080/some-uri', function(resp) {
+<pre class="prettyprint">client.post('/some-uri', function(resp) {
log.info('Got a response, status code: ' + resp.statusCode);
}).putAllHeaders({'Some-Header': 'Some-Value',
'Some-Other-Header': 'Some-Other-Value',
@@ -1513,9 +1517,9 @@ <h3 id="http-client-responses">HTTP Client Responses</h3><br/>
<p>Client responses are received as an argument to the response handler that is passed into one of the request methods on the HTTP client.</p>
<p>The response object implements <code>ReadStream</code>, so it can be pumped to a <code>WriteStream</code> like any other <code>ReadStream</code>.</p>
<p>To query the status code of the response use the <code>statusCode</code> property. The <code>statusMessage</code> property contains the status message. For example:</p>
-<pre class="prettyprint">var client = vertx.createHttpClient();
+<pre class="prettyprint">var client = vertx.createHttpClient().setHost('foo.com');
-client.getNow('http://localhost:8080/some-path', function(resp) {
+client.getNow('/some-path', function(resp) {
log.info('server returned status code: ' + resp.statusCode);
log.info('server returned status message: ' + resp.statusMessage);
});
@@ -1524,9 +1528,9 @@ <h4 id="reading-data-from-the-response-body">Reading Data from the Response Body
<p>The API for reading a http client response body is very similar to the API for reading a http server request body.</p>
<p>Sometimes an HTTP response contains a request body that we want to read. Like an HTTP request, the client response handler is called when all the response headers have arrived, not when the entire response body has arrived.</p>
<p>To receive the response body, you set a <code>dataHandler</code> on the response object which gets called as parts of the HTTP response arrive. Here's an example:</p>
-<pre class="prettyprint">var client = vertx.createHttpClient();
+<pre class="prettyprint">var client = vertx.createHttpClient().setHost('foo.com');
-client.getNow('http://localhost:8080/some-path', function(resp) {
+client.getNow('/some-path', function(resp) {
resp.dataHandler(function(buffer) {
log.info('I received ' + buffer.length() + ' bytes');
});
@@ -1535,9 +1539,9 @@ <h4 id="reading-data-from-the-response-body">Reading Data from the Response Body
<p>The response object implements the <code>ReadStream</code> interface so you can pump the response body to a <code>WriteStream</code>. See the chapter on streams and pump for a detailed explanation. </p>
<p>The <code>dataHandler</code> can be called multiple times for a single HTTP response.</p>
<p>As with a server request, if you wanted to read the entire response body before doing something with it you could do something like the following:</p>
-<pre class="prettyprint">var client = vertx.createHttpClient();
+<pre class="prettyprint">var client = vertx.createHttpClient().setHost('foo.com');
-client.getNow('http://localhost:8080/some-path', function(resp) {
+client.getNow('/some-path', function(resp) {
// Create a buffer to hold the entire response body
var body = new vertx.Buffer();
@@ -1560,9 +1564,9 @@ <h4 id="reading-data-from-the-response-body">Reading Data from the Response Body
<p>The body handler is called only once when the <em>entire</em> response body has been read.</p>
<p><em>Beware of doing this with very large responses since the entire response body will be stored in memory.</em></p>
<p>Here's an example using <code>bodyHandler</code>:</p>
-<pre class="prettyprint">var client = vertx.createHttpClient();
+<pre class="prettyprint">var client = vertx.createHttpClient().setHost('foo.com');
-client.getNow('http://localhost:8080/some-uri', function(resp) {
+client.getNow('/some-uri', function(resp) {
resp.bodyHandler(function(body) {
log.info('The total body received was ' + body.length() + ' bytes');
@@ -1579,9 +1583,9 @@ <h3 id="100-continue-handling">100-Continue Handling</h3><br/>
<p>Vert.x allows you to set a <code>continueHandler</code> on the client request object. This will be called if the server sends back a <code>Status: 100 (Continue)</code> response to signify it is ok to send the rest of the request.</p>
<p>This is used in conjunction with the <code>sendHead</code> function to send the head of the request.</p>
<p>An example will illustrate this:</p>
-<pre class="prettyprint">var client = vertx.createHttpClient();
+<pre class="prettyprint">var client = vertx.createHttpClient().setHost('foo.com');
-var request = client.put('http://localhost:8080/some-path', function(resp) {
+var request = client.put('/some-path', function(resp) {
log.info('Got a response ' + resp.statusCode);
View
56 core_manual_js.md
@@ -1185,15 +1185,19 @@ The request object has a property `method` which is a string representing what H
The request object has a property `uri` which contains the full URI (Uniform Resource Locator) of the request. For example, if the request URI was:
- http://localhost:8080/a/b/c/page.html?param1=abc&param2=xyz
+ /a/b/c/page.html?param1=abc&param2=xyz
-Then `request.uri` would contain the string `http://localhost:8080/a/b/c/page.html?param1=abc&param2=xyz`.
+Then `request.uri` would contain the string `/a/b/c/page.html?param1=abc&param2=xyz`.
+
+Request URIs can be relative or absolute (with a domain) depending on what the client sent. In many cases they will be relative.
+
+The request uri contains the value as defined in [Section 5.1.2 of the HTTP specification - Request-URI](http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html)
#### Request Path
The request object has a property `path` which contains the path of the request. For example, if the request URI was:
- http://localhost:8080/a/b/c/page.html?param1=abc&param2=xyz
+ /a/b/c/page.html?param1=abc&param2=xyz
Then `request.path` would contain the string `/a/b/c/page.html`
@@ -1201,7 +1205,7 @@ Then `request.path` would contain the string `/a/b/c/page.html`
The request object has a property `query` which contains the query of the request. For example, if the request URI was:
- http://localhost:8080/a/b/c/page.html?param1=abc&param2=xyz
+ /a/b/c/page.html?param1=abc&param2=xyz
Then `request.query` would contain the string `param1=abc&param2=xyz`
@@ -1232,7 +1236,7 @@ Similarly to the headers, the request parameters are available as the `params()`
Request parameters are sent on the request URI, after the path. For example if the URI was:
- http://localhost:8080/page.html?param1=abc&param2=xyz
+ /page.html?param1=abc&param2=xyz
Then the params hash would be the following JS object:
@@ -1487,7 +1491,7 @@ This, of course, can be chained:
A single `HTTPClient` always connects to the same host and port. If you want to connect to different servers, create more instances.
-The default value for hostname is `localhost`, and the default value for port is `80`.
+The default port is `80` and the default host is `localhost`. So if you don't explicitly set these values that's what the client will attempt to connect to.
### Pooling and Keep Alive
@@ -1537,15 +1541,19 @@ Legal request methods are: `get`, `put`, `post`, `delete`, `head`, `options`, `c
The general modus operandi is you invoke the appropriate method passing in the request URI as the first parameter, the second parameter is an event handler which will get called when the corresponding response arrives. The response handler is passed the client response object as an argument.
+The value specified in the request URI corresponds to the Request-URI as specified in [Section 5.1.2 of the HTTP specification](http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html). In most cases it will be a relative URI.
+
+*Please note that the domain/port that the client connects to is determined by `setPort` and `setHost`, and is not parsed from the uri.*
+
The return value from the appropriate request method is an `HTTPClientRequest` object. You can use this to add headers to the request, and to write to the request body. The request object implements `WriteStream`.
Once you have finished with the request you must call the `end` function.
If you don't know the name of the request method in advance there is a general `request` method which takes the HTTP method as a parameter:
- var client = vertx.createHttpClient();
+ var client = vertx.createHttpClient().setHost('foo.com');
- var request = client.request('POST', 'http://localhost:8080/some-path', function(resp) {
+ var request = client.request('POST', '/some-path', function(resp) {
log.info('Got a response, status code: ' + resp.statusCode);
});
@@ -1553,9 +1561,9 @@ If you don't know the name of the request method in advance there is a general `
There is also a method called `getNow` which does the same as `get`, but automatically ends the request. This is useful for simple GETs which don't have a request body:
- var client = vertx.createHttpClient();
+ var client = vertx.createHttpClient().setHost('foo.com');
- client.getNow('http://localhost:8080/some-path', function(resp) {
+ client.getNow('/some-path', function(resp) {
log.info('Got a response, status code: ' + resp.statusCode);
});
@@ -1611,9 +1619,9 @@ The function can also be called with a string or Buffer in the same way `write`
To write headers to the request you can just add them to the headers hash:
- var client = vertx.createHttpClient();
+ var client = vertx.createHttpClient().setHost('foo.com');
- var request = client.post('http://localhost:8080/some-path', function(resp) {
+ var request = client.post('/some-path', function(resp) {
log.info('Got a response, status code: ' + resp.statusCode);
});
@@ -1622,7 +1630,7 @@ To write headers to the request you can just add them to the headers hash:
Or you can use the `putHeader` method if you prefer a more fluent API:
- client.post('http://localhost:8080/some-uri', function(resp) {
+ client.post('/some-uri', function(resp) {
log.info('Got a response, status code: ' + resp.statusCode);
}).putHeader('Some-Header', 'Some-Value')
.putHeader('Some-Other-Header', 'Some-Other-Value')
@@ -1630,7 +1638,7 @@ Or you can use the `putHeader` method if you prefer a more fluent API:
If you want to put more than one header at the same time, you can instead use the `putAllHeaders` function.
- client.post('http://localhost:8080/some-uri', function(resp) {
+ client.post('/some-uri', function(resp) {
log.info('Got a response, status code: ' + resp.statusCode);
}).putAllHeaders({'Some-Header': 'Some-Value',
'Some-Other-Header': 'Some-Other-Value',
@@ -1657,9 +1665,9 @@ The response object implements `ReadStream`, so it can be pumped to a `WriteStre
To query the status code of the response use the `statusCode` property. The `statusMessage` property contains the status message. For example:
- var client = vertx.createHttpClient();
+ var client = vertx.createHttpClient().setHost('foo.com');
- client.getNow('http://localhost:8080/some-path', function(resp) {
+ client.getNow('/some-path', function(resp) {
log.info('server returned status code: ' + resp.statusCode);
log.info('server returned status message: ' + resp.statusMessage);
});
@@ -1673,9 +1681,9 @@ Sometimes an HTTP response contains a request body that we want to read. Like an
To receive the response body, you set a `dataHandler` on the response object which gets called as parts of the HTTP response arrive. Here's an example:
- var client = vertx.createHttpClient();
+ var client = vertx.createHttpClient().setHost('foo.com');
- client.getNow('http://localhost:8080/some-path', function(resp) {
+ client.getNow('/some-path', function(resp) {
resp.dataHandler(function(buffer) {
log.info('I received ' + buffer.length() + ' bytes');
});
@@ -1687,9 +1695,9 @@ The `dataHandler` can be called multiple times for a single HTTP response.
As with a server request, if you wanted to read the entire response body before doing something with it you could do something like the following:
- var client = vertx.createHttpClient();
+ var client = vertx.createHttpClient().setHost('foo.com');
- client.getNow('http://localhost:8080/some-path', function(resp) {
+ client.getNow('/some-path', function(resp) {
// Create a buffer to hold the entire response body
var body = new vertx.Buffer();
@@ -1718,9 +1726,9 @@ The body handler is called only once when the *entire* response body has been re
Here's an example using `bodyHandler`:
- var client = vertx.createHttpClient();
+ var client = vertx.createHttpClient().setHost('foo.com');
- client.getNow('http://localhost:8080/some-uri', function(resp) {
+ client.getNow('/some-uri', function(resp) {
resp.bodyHandler(function(body) {
log.info('The total body received was ' + body.length() + ' bytes');
@@ -1746,9 +1754,9 @@ This is used in conjunction with the `sendHead` function to send the head of the
An example will illustrate this:
- var client = vertx.createHttpClient();
+ var client = vertx.createHttpClient().setHost('foo.com');
- var request = client.put('http://localhost:8080/some-path', function(resp) {
+ var request = client.put('/some-path', function(resp) {
log.info('Got a response ' + resp.statusCode);
View
48 core_manual_python.html
@@ -1184,17 +1184,19 @@ <h4 id="request-method">Request Method</h4><br/>
<p>The request object has a property <code>method</code> which is a string representing what HTTP method was requested. Possible values for <code>method</code> are: <code>GET</code>, <code>PUT</code>, <code>POST</code>, <code>DELETE</code>, <code>HEAD</code>, <code>OPTIONS</code>, <code>CONNECT</code>, <code>TRACE</code>, <code>PATCH</code>.</p>
<h4 id="request-uri">Request URI</h4><br/>
<p>The request object has a property <code>uri</code> which contains the full URI (Uniform Resource Locator) of the request. For example, if the request URI was:</p>
-<pre class="prettyprint">http://localhost:8080/a/b/c/page.html?param1=abc&amp;param2=xyz
+<pre class="prettyprint">/a/b/c/page.html?param1=abc&amp;param2=xyz
</pre>
-<p>Then <code>request.uri</code> would contain the string <code>http://localhost:8080/a/b/c/page.html?param1=abc&amp;param2=xyz</code>.</p>
+<p>Then <code>request.uri</code> would contain the string <code>/a/b/c/page.html?param1=abc&amp;param2=xyz</code>.</p>
+<p>Request URIs can be relative or absolute (with a domain) depending on what the client sent. In many cases they will be relative.</p>
+<p>The request uri contains the value as defined in <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html">Section 5.1.2 of the HTTP specification - Request-URI</a></p>
<h4 id="request-path">Request Path</h4><br/>
<p>The request object has a property <code>path</code> which contains the path of the request. For example, if the request URI was:</p>
-<pre class="prettyprint">http://localhost:8080/a/b/c/page.html?param1=abc&amp;param2=xyz
+<pre class="prettyprint">/a/b/c/page.html?param1=abc&amp;param2=xyz
</pre>
<p>Then <code>request.path</code> would contain the string <code>/a/b/c/page.html</code></p>
<h4 id="request-query">Request Query</h4><br/>
<p>The request object has a property <code>query</code> which contains the query of the request. For example, if the request URI was:</p>
-<pre class="prettyprint">http://localhost:8080/a/b/c/page.html?param1=abc&amp;param2=xyz
+<pre class="prettyprint">/a/b/c/page.html?param1=abc&amp;param2=xyz
</pre>
<p>Then <code>request.query</code> would contain the string <code>param1=abc&amp;param2=xyz</code></p>
<h4 id="request-headers">Request Headers</h4><br/>
@@ -1218,7 +1220,7 @@ <h4 id="request-headers">Request Headers</h4><br/>
<h4 id="request-params">Request params</h4><br/>
<p>Similarly to the headers, the request parameters are available using the <code>params</code> method on the request object. The return value of the function is just a Hash too.</p>
<p>Request parameters are sent on the request URI, after the path. For example if the URI was:</p>
-<pre class="prettyprint">http://localhost:8080/page.html?param1=abc&amp;param2=xyz
+<pre class="prettyprint">/page.html?param1=abc&amp;param2=xyz
</pre>
<p>Then the params hash would be the following JS object:</p>
<pre class="prettyprint">{ param1: 'abc', param2: 'xyz' }
@@ -1407,7 +1409,7 @@ <h3 id="creating-an-http-client">Creating an HTTP Client</h3><br/>
client.host = 'foo.com'
</pre>
<p>A single <code>HttpClient</code> always connects to the same host and port. If you want to connect to different servers, create more instances.</p>
-<p>The default value for hostname is <code>localhost</code>, and the default value for port is <code>80</code>.</p>
+<p>The default port is <code>80</code> and the default host is <code>localhost</code>. So if you don't explicitly set these values that's what the client will attempt to connect to.</p>
<h3 id="pooling-and-keep-alive">Pooling and Keep Alive</h3><br/>
<p>By default the <code>HttpClient</code> pools HTTP connections. As you make requests a connection is borrowed from the pool and returned when the HTTP response has ended.</p>
<p>If you do not want connections to be pooled you can set <code>keep_alive</code> to <code>False</code>:</p>
@@ -1430,23 +1432,27 @@ <h3 id="making-requests">Making Requests</h3><br/>
<pre class="prettyprint">import vertx
client = vertx.create_http_client()
+client.host = 'foo.com'
def response_handler(resp): print "got response %s"% resp.status_code
-request = client.post('http://localhost:8080/some-path/', response_handler)
+request = client.post('/some-path/', response_handler)
request.end()
</pre>
<p>To make a PUT request use the <code>put</code> method, to make a GET request use the <code>get</code> method, etc.</p>
<p>Legal request methods are: <code>get</code>, <code>put</code>, <code>post</code>, <code>delete</code>, <code>head</code>, <code>options</code>, <code>connect</code>, <code>trace</code> and <code>patch</code>.</p>
<p>The general modus operandi is you invoke the appropriate method passing in the request URI as the first parameter, the second parameter is an event handler which will get called when the corresponding response arrives. The response handler is passed the client response object as an argument.</p>
+<p>The value specified in the request URI corresponds to the Request-URI as specified in <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html">Section 5.1.2 of the HTTP specification</a>. In most cases it will be a relative URI.</p>
+<p><em>Please note that the domain/port that the client connects to is determined by <code>setPort</code> and <code>setHost</code>, and is not parsed from the uri.</em></p>
<p>The return value from the appropriate request method is an <code>HttpClientRequest</code> object. You can use this to add headers to the request, and to write to the request body. The request object implements <code>WriteStream</code>.</p>
<p>Once you have finished with the request you must call the <code>end</code> method.</p>
<p>If you don't know the name of the request method in advance there is a general <code>request</code> method which takes the HTTP method as a parameter:</p>
<pre class="prettyprint">import vertx
client = vertx.create_http_client()
+client.host = 'foo.com'
def response_handler(resp): print "got response %s"% resp.status_code
-request = client.request('POST', 'http://localhost:8080/some-path/', response_handler)
+request = client.request('POST', '/some-path/', response_handler)
request.end()
</pre>
@@ -1454,9 +1460,10 @@ <h3 id="making-requests">Making Requests</h3><br/>
<pre class="prettyprint">import vertx
client = vertx.create_http_client()
+client.host = 'foo.com'
def response_handler(resp): print "got response %s"% resp.status_code
-client.get_now('http://localhost:8080/some-path/', response_handler)
+client.get_now('/some-path/', response_handler)
</pre>
<p>With <code>get_now</code> there is no return value.</p>
<h4 id="writing-to-the-request-body">Writing to the request body</h4><br/>
@@ -1490,10 +1497,11 @@ <h4 id="ending-http-requests">Ending HTTP requests</h4><br/>
<h4 id="writing-request-headers">Writing Request Headers</h4><br/>
<p>To write headers to the request, add them to the Hash returned from the <code>headers</code> method:</p>
<pre class="prettyprint">client = vertx.create_http_client()
+client.host = 'foo.com'
def response_handler(resp): print "got response %s"% resp.status_code
-request = client.post('http://localhost:8080/some-path', response_handler)
+request = client.post('/some-path', response_handler)
request.headers['Some-Header'] = 'Some-Value'
request.end()
@@ -1501,10 +1509,11 @@ <h4 id="writing-request-headers">Writing Request Headers</h4><br/>
<p>You can also use the <code>put_header</code> method to enable a more fluent API: <br/>
</p>
<pre class="prettyprint">client = vertx.create_http_client()
+client.host = 'foo.com'
def response_handler(resp): print "got response %s"% resp.status_code
-request = client.post('http://localhost:8080/some-path', response_handler).
+request = client.post('/some-path', response_handler).
put_header('Some-Header', 'Some-Value').
put_header('Some-Other-Header', 'Some-Other-Value').
end()
@@ -1520,30 +1529,33 @@ <h3 id="http-client-responses">HTTP Client Responses</h3><br/>
<p>The response object implements <code>ReadStream</code>, so it can be pumped to a <code>WriteStream</code> like any other <code>ReadStream</code>.</p>
<p>To query the status code of the response use the <code>status_code</code> property. The <code>status_message</code> property contains the status message. For example:</p>
<pre class="prettyprint">client = vertx.create_http_client()
+client.host = 'foo.com'
def response_handler(resp):
print "server returned status code: %s"% resp.status_code
print "server returned status message: %s"% resp.status_message
-client.get_now('http://localhost:8080/some-path', response_handler)
+client.get_now('/some-path', response_handler)
</pre>
<h4 id="reading-data-from-the-response-body">Reading Data from the Response Body</h4><br/>
<p>The API for reading a http client response body is very similar to the API for reading a http server request body.</p>
<p>Sometimes an HTTP response contains a request body that we want to read. Like an HTTP request, the client response handler is called when all the response headers have arrived, not when the entire response body has arrived.</p>
<p>To receive the response body, you set a <code>dataHandler</code> on the response object which gets called as parts of the HTTP response arrive. Here's an example:</p>
<pre class="prettyprint">client = vertx.create_http_client()
+client.host = 'foo.com'
def response_handler(resp):
@resp.data_handler
def data_handler(buffer):
print "I received %s bytes"% buffer.length
-client.get_now('http://localhost:8080/some-path', response_handler)
+client.get_now('/some-path', response_handler)
</pre>
<p>The response object implements the <code>ReadStream</code> interface so you can pump the response body to a <code>WriteStream</code>. See the chapter on streams and pump for a detailed explanation.</p>
<p>The <code>data_handler</code> can be called multiple times for a single HTTP response.</p>
<p>As with a server request, if you wanted to read the entire response body before doing something with it you could do something like the following:</p>
<pre class="prettyprint">client = vertx.create_http_client()
+client.host = 'foo.com'
def response_handler(resp):
@@ -1559,7 +1571,7 @@ <h4 id="reading-data-from-the-response-body">Reading Data from the Response Body
# The entire response body has been received
print "The total body received was %s bytes"% body.length
-client.get_now('http://localhost:8080/some-path', response_handler)
+client.get_now('/some-path', response_handler)
</pre>
<p>Like any <code>ReadStream</code> the end handler is invoked when the end of stream is reached - in this case at the end of the response.</p>
<p>If the HTTP response is using HTTP chunking, then each chunk of the response body will correspond to a single call to the <code>data_handler</code>.</p>
@@ -1568,12 +1580,13 @@ <h4 id="reading-data-from-the-response-body">Reading Data from the Response Body
<p><em>Beware of doing this with very large responses since the entire response body will be stored in memory.</em></p>
<p>Here's an example using <code>body_handler</code>:</p>
<pre class="prettyprint">client = vertx.create_http_client()
+client.host = 'foo.com'
def response_handler(resp):
@resp.body_handler
def body_handler(body):
print "The total body received was %s bytes"% body.length
-client.get_now('http://localhost:8080/some-path', response_handler)
+client.get_now('/some-path', response_handler)
</pre>
<h2 id="pumping-requests-and-responses">Pumping Requests and Responses</h2><br/>
<p>The HTTP client and server requests and responses all implement either <code>ReadStream</code> or <code>WriteStream</code>. This means you can pump between them and any other read and write streams.</p>
@@ -1585,10 +1598,11 @@ <h3 id="100-continue-handling">100-Continue Handling</h3><br/>
<p>This is used in conjunction with the <code>send_head</code> function to send the head of the request.</p>
<p>An example will illustrate this:</p>
<pre class="prettyprint">client = vertx.create_http_client()
+client.host = 'foo.com'
def response_handler(resp):
print "Got a response: %s"% resp.status_code
-request = client.put('http://localhost:8080/some-path', response_handler)
+request = client.put('/some-path', response_handler)
request.put_header('Expect', '100-Continue')
request.chunked = True
@@ -1966,7 +1980,7 @@ <h2 id="securing-the-bridge">Securing the Bridge</h2><br/>
'wibble' : 'foo'
}
}
- ])
+ ], [{}])
server.listen(8080)
</pre>
View
52 core_manual_python.md
@@ -1220,15 +1220,19 @@ The request object has a property `method` which is a string representing what H
The request object has a property `uri` which contains the full URI (Uniform Resource Locator) of the request. For example, if the request URI was:
- http://localhost:8080/a/b/c/page.html?param1=abc&param2=xyz
+ /a/b/c/page.html?param1=abc&param2=xyz
+
+Then `request.uri` would contain the string `/a/b/c/page.html?param1=abc&param2=xyz`.
+
+Request URIs can be relative or absolute (with a domain) depending on what the client sent. In many cases they will be relative.
-Then `request.uri` would contain the string `http://localhost:8080/a/b/c/page.html?param1=abc&param2=xyz`.
+The request uri contains the value as defined in [Section 5.1.2 of the HTTP specification - Request-URI](http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html)
#### Request Path
The request object has a property `path` which contains the path of the request. For example, if the request URI was:
- http://localhost:8080/a/b/c/page.html?param1=abc&param2=xyz
+ /a/b/c/page.html?param1=abc&param2=xyz
Then `request.path` would contain the string `/a/b/c/page.html`
@@ -1236,7 +1240,7 @@ Then `request.path` would contain the string `/a/b/c/page.html`
The request object has a property `query` which contains the query of the request. For example, if the request URI was:
- http://localhost:8080/a/b/c/page.html?param1=abc&param2=xyz
+ /a/b/c/page.html?param1=abc&param2=xyz
Then `request.query` would contain the string `param1=abc&param2=xyz`
@@ -1268,7 +1272,7 @@ Similarly to the headers, the request parameters are available using the `params
Request parameters are sent on the request URI, after the path. For example if the URI was:
- http://localhost:8080/page.html?param1=abc&param2=xyz
+ /page.html?param1=abc&param2=xyz
Then the params hash would be the following JS object:
@@ -1521,7 +1525,7 @@ You set the port and hostname (or ip address) that the client will connect to us
A single `HttpClient` always connects to the same host and port. If you want to connect to different servers, create more instances.
-The default value for hostname is `localhost`, and the default value for port is `80`.
+The default port is `80` and the default host is `localhost`. So if you don't explicitly set these values that's what the client will attempt to connect to.
### Pooling and Keep Alive
@@ -1556,9 +1560,10 @@ For example, to make a `POST` request:
import vertx
client = vertx.create_http_client()
+ client.host = 'foo.com'
def response_handler(resp): print "got response %s"% resp.status_code
- request = client.post('http://localhost:8080/some-path/', response_handler)
+ request = client.post('/some-path/', response_handler)
request.end()
@@ -1568,6 +1573,10 @@ Legal request methods are: `get`, `put`, `post`, `delete`, `head`, `options`, `c
The general modus operandi is you invoke the appropriate method passing in the request URI as the first parameter, the second parameter is an event handler which will get called when the corresponding response arrives. The response handler is passed the client response object as an argument.
+The value specified in the request URI corresponds to the Request-URI as specified in [Section 5.1.2 of the HTTP specification](http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html). In most cases it will be a relative URI.
+
+*Please note that the domain/port that the client connects to is determined by `setPort` and `setHost`, and is not parsed from the uri.*
+
The return value from the appropriate request method is an `HttpClientRequest` object. You can use this to add headers to the request, and to write to the request body. The request object implements `WriteStream`.
Once you have finished with the request you must call the `end` method.
@@ -1577,8 +1586,9 @@ If you don't know the name of the request method in advance there is a general `
import vertx
client = vertx.create_http_client()
+ client.host = 'foo.com'
def response_handler(resp): print "got response %s"% resp.status_code
- request = client.request('POST', 'http://localhost:8080/some-path/', response_handler)
+ request = client.request('POST', '/some-path/', response_handler)
request.end()
@@ -1587,9 +1597,10 @@ There is also a method called `get_now` which does the same as `get`, but automa
import vertx
client = vertx.create_http_client()
+ client.host = 'foo.com'
def response_handler(resp): print "got response %s"% resp.status_code
- client.get_now('http://localhost:8080/some-path/', response_handler)
+ client.get_now('/some-path/', response_handler)
With `get_now` there is no return value.
@@ -1643,10 +1654,11 @@ The method can also be called with a string or Buffer in the same way write is c
To write headers to the request, add them to the Hash returned from the `headers` method:
client = vertx.create_http_client()
+ client.host = 'foo.com'
def response_handler(resp): print "got response %s"% resp.status_code
- request = client.post('http://localhost:8080/some-path', response_handler)
+ request = client.post('/some-path', response_handler)
request.headers['Some-Header'] = 'Some-Value'
request.end()
@@ -1654,10 +1666,11 @@ To write headers to the request, add them to the Hash returned from the `headers
You can also use the `put_header` method to enable a more fluent API:
client = vertx.create_http_client()
+ client.host = 'foo.com'
def response_handler(resp): print "got response %s"% resp.status_code
- request = client.post('http://localhost:8080/some-path', response_handler).
+ request = client.post('/some-path', response_handler).
put_header('Some-Header', 'Some-Value').
put_header('Some-Other-Header', 'Some-Other-Value').
end()
@@ -1681,12 +1694,13 @@ The response object implements `ReadStream`, so it can be pumped to a `WriteStre
To query the status code of the response use the `status_code` property. The `status_message` property contains the status message. For example:
client = vertx.create_http_client()
+ client.host = 'foo.com'
def response_handler(resp):
print "server returned status code: %s"% resp.status_code
print "server returned status message: %s"% resp.status_message
- client.get_now('http://localhost:8080/some-path', response_handler)
+ client.get_now('/some-path', response_handler)
#### Reading Data from the Response Body
@@ -1697,13 +1711,14 @@ Sometimes an HTTP response contains a request body that we want to read. Like an
To receive the response body, you set a `dataHandler` on the response object which gets called as parts of the HTTP response arrive. Here's an example:
client = vertx.create_http_client()
+ client.host = 'foo.com'
def response_handler(resp):
@resp.data_handler
def data_handler(buffer):
print "I received %s bytes"% buffer.length
- client.get_now('http://localhost:8080/some-path', response_handler)
+ client.get_now('/some-path', response_handler)
The response object implements the `ReadStream` interface so you can pump the response body to a `WriteStream`. See the chapter on streams and pump for a detailed explanation.
@@ -1712,6 +1727,7 @@ The `data_handler` can be called multiple times for a single HTTP response.
As with a server request, if you wanted to read the entire response body before doing something with it you could do something like the following:
client = vertx.create_http_client()
+ client.host = 'foo.com'
def response_handler(resp):
@@ -1727,7 +1743,7 @@ As with a server request, if you wanted to read the entire response body before
# The entire response body has been received
print "The total body received was %s bytes"% body.length
- client.get_now('http://localhost:8080/some-path', response_handler)
+ client.get_now('/some-path', response_handler)
Like any `ReadStream` the end handler is invoked when the end of stream is reached - in this case at the end of the response.
@@ -1743,12 +1759,13 @@ The body handler is called only once when the *entire* response body has been re
Here's an example using `body_handler`:
client = vertx.create_http_client()
+ client.host = 'foo.com'
def response_handler(resp):
@resp.body_handler
def body_handler(body):
print "The total body received was %s bytes"% body.length
- client.get_now('http://localhost:8080/some-path', response_handler)
+ client.get_now('/some-path', response_handler)
## Pumping Requests and Responses
@@ -1770,10 +1787,11 @@ This is used in conjunction with the `send_head` function to send the head of th
An example will illustrate this:
client = vertx.create_http_client()
+ client.host = 'foo.com'
def response_handler(resp):
print "Got a response: %s"% resp.status_code
- request = client.put('http://localhost:8080/some-path', response_handler)
+ request = client.put('/some-path', response_handler)
request.put_header('Expect', '100-Continue')
request.chunked = True
@@ -2252,7 +2270,7 @@ Here is an example:
'wibble' : 'foo'
}
}
- ])
+ ], [{}])
server.listen(8080)
View
46 core_manual_ruby.html
@@ -1133,17 +1133,19 @@ <h4 id="request-method">Request Method</h4><br/>
<p>The request object has a property <code>method</code> which is a string representing what HTTP method was requested. Possible values for <code>method</code> are: <code>GET</code>, <code>PUT</code>, <code>POST</code>, <code>DELETE</code>, <code>HEAD</code>, <code>OPTIONS</code>, <code>CONNECT</code>, <code>TRACE</code>, <code>PATCH</code>.</p>
<h4 id="request-uri">Request URI</h4><br/>
<p>The request object has a property <code>uri</code> which contains the full URI (Uniform Resource Locator) of the request. For example, if the request URI was:</p>
-<pre class="prettyprint">http://localhost:8080/a/b/c/page.html?param1=abc&amp;param2=xyz
+<pre class="prettyprint">/a/b/c/page.html?param1=abc&amp;param2=xyz
</pre>
-<p>Then <code>request.uri</code> would contain the string <code>http://localhost:8080/a/b/c/page.html?param1=abc&amp;param2=xyz</code>.</p>
+<p>Then <code>request.uri</code> would contain the string <code>/a/b/c/page.html?param1=abc&amp;param2=xyz</code>.</p>
+<p>Request URIs can be relative or absolute (with a domain) depending on what the client sent. In many cases they will be relative.</p>
+<p>The request uri contains the value as defined in <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html">Section 5.1.2 of the HTTP specification - Request-URI</a></p>
<h4 id="request-path">Request Path</h4><br/>
<p>The request object has a property <code>path</code> which contains the path of the request. For example, if the request URI was:</p>
-<pre class="prettyprint">http://localhost:8080/a/b/c/page.html?param1=abc&amp;param2=xyz
+<pre class="prettyprint">/a/b/c/page.html?param1=abc&amp;param2=xyz
</pre>
<p>Then <code>request.path</code> would contain the string <code>/a/b/c/page.html</code></p>
<h4 id="request-query">Request Query</h4><br/>
<p>The request object has a property <code>query</code> which contains the query of the request. For example, if the request URI was:</p>
-<pre class="prettyprint">http://localhost:8080/a/b/c/page.html?param1=abc&amp;param2=xyz
+<pre class="prettyprint">/a/b/c/page.html?param1=abc&amp;param2=xyz
</pre>
<p>Then <code>request.query</code> would contain the string <code>param1=abc&amp;param2=xyz</code></p>
<h4 id="request-headers">Request Headers</h4><br/>
@@ -1166,7 +1168,7 @@ <h4 id="request-headers">Request Headers</h4><br/>
<h4 id="request-params">Request params</h4><br/>
<p>Similarly to the headers, the request parameters are available using the <code>params</code> method on the request object. The return value of the function is just a Hash too.</p>
<p>Request parameters are sent on the request URI, after the path. For example if the URI was:</p>
-<pre class="prettyprint">http://localhost:8080/page.html?param1=abc&amp;param2=xyz
+<pre class="prettyprint">/page.html?param1=abc&amp;param2=xyz
</pre>
<p>Then the params hash would be the following JS object:</p>
<pre class="prettyprint">{ param1: 'abc', param2: 'xyz' }
@@ -1339,7 +1341,7 @@ <h3 id="creating-an-http-client">Creating an HTTP Client</h3><br/>
client.host = 'foo.com'
</pre>
<p>A single <code>HttpClient</code> always connects to the same host and port. If you want to connect to different servers, create more instances.</p>
-<p>The default value for hostname is <code>localhost</code>, and the default value for port is <code>80</code>.</p>
+<p>The default port is <code>80</code> and the default host is <code>localhost</code>. So if you don't explicitly set these values that's what the client will attempt to connect to.</p>
<h3 id="pooling-and-keep-alive">Pooling and Keep Alive</h3><br/>
<p>By default the <code>HttpClient</code> pools HTTP connections. As you make requests a connection is borrowed from the pool and returned when the HTTP response has ended.</p>
<p>If you do not want connections to be pooled you can call <code>setKeepAlive</code> with <code>false</code>:</p>
@@ -1360,8 +1362,9 @@ <h3 id="making-requests">Making Requests</h3><br/>
<p>To make a request using the client you invoke one the methods named after the HTTP method that you want to invoke.</p>
<p>For example, to make a <code>POST</code> request:</p>
<pre class="prettyprint">client = Vertx::HttpClient.new
+client.host = 'foo.com'
-request = client.post('http://localhost:8080/some-path/') do |resp|
+request = client.post('/some-path/') do |resp|
puts "got response #{resp.status_code}"
end
@@ -1370,12 +1373,15 @@ <h3 id="making-requests">Making Requests</h3><br/>
<p>To make a PUT request use the <code>put</code> method, to make a GET request use the <code>get</code> method, etc.</p>
<p>Legal request methods are: <code>get</code>, <code>put</code>, <code>post</code>, <code>delete</code>, <code>head</code>, <code>options</code>, <code>connect</code>, <code>trace</code> and <code>patch</code>.</p>
<p>The general modus operandi is you invoke the appropriate method passing in the request URI as the first parameter, the second parameter is an event handler which will get called when the corresponding response arrives. The response handler is passed the client response object as an argument.</p>
+<p>The value specified in the request URI corresponds to the Request-URI as specified in <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html">Section 5.1.2 of the HTTP specification</a>. In most cases it will be a relative URI.</p>
+<p><em>Please note that the domain/port that the client connects to is determined by <code>setPort</code> and <code>setHost</code>, and is not parsed from the uri.</em></p>
<p>The return value from the appropriate request method is an <code>HttpClientRequest</code> object. You can use this to add headers to the request, and to write to the request body. The request object implements <code>WriteStream</code>.</p>
<p>Once you have finished with the request you must call the <code>end</code> method.</p>
<p>If you don't know the name of the request method in advance there is a general <code>request</code> method which takes the HTTP method as a parameter:</p>
<pre class="prettyprint">client = Vertx::HttpClient.new
+client.host = 'foo.com'
-request = client.request('POST', 'http://localhost:8080/some-path/') do |resp|
+request = client.request('POST', '/some-path/') do |resp|
puts "got response #{resp.status_code}"
end
@@ -1383,8 +1389,9 @@ <h3 id="making-requests">Making Requests</h3><br/>
</pre>
<p>There is also a method called <code>get_now</code> which does the same as <code>get</code>, but automatically ends the request. This is useful for simple GETs which don't have a request body:</p>
<pre class="prettyprint">client = Vertx::HttpClient.new
+client.host = 'foo.com'
-client.get_now('http://localhost:8080/some-path/') do |resp|
+client.get_now('/some-path/') do |resp|
puts "got response #{resp.status_code}"
end
</pre>
@@ -1419,8 +1426,9 @@ <h4 id="ending-http-requests">Ending HTTP requests</h4><br/>
<h4 id="writing-request-headers">Writing Request Headers</h4><br/>
<p>To write headers to the request, add them to the Hash returned from the <code>headers</code> method:</p>
<pre class="prettyprint">client = Vertx::HttpClient.new
+client.host = 'foo.com'
-request = client.post('http://localhost:8080/some-path') do |resp|
+request = client.post('/some-path') do |resp|
puts "got response #{resp.status_code}"
end
@@ -1430,8 +1438,9 @@ <h4 id="writing-request-headers">Writing Request Headers</h4><br/>
<p>You can also use the <code>put_header</code> method to enable a more fluent API: <br/>
</p>
<pre class="prettyprint">client = Vertx::HttpClient.new
+client.host = 'foo.com'
-request = client.post('http://localhost:8080/some-path') do |resp|
+request = client.post('/some-path') do |resp|
puts "got response #{resp.status_code}"
end.put_header('Some-Header', 'Some-Value').
put_header('Some-Other-Header', 'Some-Other-Value').
@@ -1448,8 +1457,9 @@ <h3 id="http-client-responses">HTTP Client Responses</h3><br/>
<p>The response object implements <code>ReadStream</code>, so it can be pumped to a <code>WriteStream</code> like any other <code>ReadStream</code>.</p>
<p>To query the status code of the response use the <code>status_code</code> property. The <code>status_message</code> property contains the status message. For example:</p>
<pre class="prettyprint">client = Vertx::HttpClient.new
+client.host = 'foo.com'
-client.get_now('http://localhost:8080/some-path') do |resp|
+client.get_now('/some-path') do |resp|
puts "server returned status code: #{resp.status_code}"
puts "server returned status message: #{resp.status_message}"
end
@@ -1459,8 +1469,9 @@ <h4 id="reading-data-from-the-response-body">Reading Data from the Response Body
<p>Sometimes an HTTP response contains a request body that we want to read. Like an HTTP request, the client response handler is called when all the response headers have arrived, not when the entire response body has arrived.</p>
<p>To receive the response body, you set a <code>dataHandler</code> on the response object which gets called as parts of the HTTP response arrive. Here's an example:</p>
<pre class="prettyprint">client = Vertx::HttpClient.new
+client.host = 'foo.com'
-client.get_now('http://localhost:8080/some-path') do |resp|
+client.get_now('/some-path') do |resp|
resp.data_handler { |buffer| puts "I received #{buffer.length} bytes" }
end
</pre>
@@ -1468,8 +1479,9 @@ <h4 id="reading-data-from-the-response-body">Reading Data from the Response Body
<p>The <code>data_handler</code> can be called multiple times for a single HTTP response.</p>
<p>As with a server request, if you wanted to read the entire response body before doing something with it you could do something like the following:</p>
<pre class="prettyprint">client = Vertx::HttpClient.new
+client.host = 'foo.com'
-client.get_now('http://localhost:8080/some-path') do |resp|
+client.get_now('/some-path') do |resp|
# Create a buffer to hold the entire response body
body = Vertx::Buffer.create(0)
@@ -1493,8 +1505,9 @@ <h4 id="reading-data-from-the-response-body">Reading Data from the Response Body
<p><em>Beware of doing this with very large responses since the entire response body will be stored in memory.</em></p>
<p>Here's an example using <code>body_handler</code>:</p>
<pre class="prettyprint">client = Vertx::HttpClient.new
+client.host = 'foo.com'
-client.get_now('http://localhost:8080/some-path') do |resp|
+client.get_now('/some-path') do |resp|
resp.body_handler do |body|
puts "The total body received was #{body.length} bytes"
@@ -1512,8 +1525,9 @@ <h3 id="100-continue-handling">100-Continue Handling</h3><br/>
<p>This is used in conjunction with the <code>send_head</code> function to send the head of the request.</p>
<p>An example will illustrate this:</p>
<pre class="prettyprint">client = Vertx::HttpClient.new
+client.host = 'foo.com'
-request = client.put('http://localhost:8080/some-path') do |resp|
+request = client.put('/some-path') do |resp|
puts "Got a response: #{resp.status_code}"
View
56 core_manual_ruby.md
@@ -1168,15 +1168,19 @@ The request object has a property `method` which is a string representing what H
The request object has a property `uri` which contains the full URI (Uniform Resource Locator) of the request. For example, if the request URI was:
- http://localhost:8080/a/b/c/page.html?param1=abc&param2=xyz
+ /a/b/c/page.html?param1=abc&param2=xyz
+
+Then `request.uri` would contain the string `/a/b/c/page.html?param1=abc&param2=xyz`.
+
+Request URIs can be relative or absolute (with a domain) depending on what the client sent. In many cases they will be relative.
-Then `request.uri` would contain the string `http://localhost:8080/a/b/c/page.html?param1=abc&param2=xyz`.
+The request uri contains the value as defined in [Section 5.1.2 of the HTTP specification - Request-URI](http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html)
#### Request Path
The request object has a property `path` which contains the path of the request. For example, if the request URI was:
- http://localhost:8080/a/b/c/page.html?param1=abc&param2=xyz
+ /a/b/c/page.html?param1=abc&param2=xyz
Then `request.path` would contain the string `/a/b/c/page.html`
@@ -1184,7 +1188,7 @@ Then `request.path` would contain the string `/a/b/c/page.html`
The request object has a property `query` which contains the query of the request. For example, if the request URI was:
- http://localhost:8080/a/b/c/page.html?param1=abc&param2=xyz
+ /a/b/c/page.html?param1=abc&param2=xyz
Then `request.query` would contain the string `param1=abc&param2=xyz`
@@ -1215,7 +1219,7 @@ Similarly to the headers, the request parameters are available using the `params
Request parameters are sent on the request URI, after the path. For example if the URI was:
- http://localhost:8080/page.html?param1=abc&param2=xyz
+ /page.html?param1=abc&param2=xyz
Then the params hash would be the following JS object:
@@ -1452,7 +1456,7 @@ You set the port and hostname (or ip address) that the client will connect to us
A single `HttpClient` always connects to the same host and port. If you want to connect to different servers, create more instances.
-The default value for hostname is `localhost`, and the default value for port is `80`.
+The default port is `80` and the default host is `localhost`. So if you don't explicitly set these values that's what the client will attempt to connect to.
### Pooling and Keep Alive
@@ -1484,9 +1488,10 @@ To make a request using the client you invoke one the methods named after the HT
For example, to make a `POST` request:
- client = Vertx::HttpClient.new
+ client = Vertx::HttpClient.new
+ client.host = 'foo.com'
- request = client.post('http://localhost:8080/some-path/') do |resp|
+ request = client.post('/some-path/') do |resp|
puts "got response #{resp.status_code}"
end
@@ -1498,15 +1503,20 @@ Legal request methods are: `get`, `put`, `post`, `delete`, `head`, `options`, `c
The general modus operandi is you invoke the appropriate method passing in the request URI as the first parameter, the second parameter is an event handler which will get called when the corresponding response arrives. The response handler is passed the client response object as an argument.
+The value specified in the request URI corresponds to the Request-URI as specified in [Section 5.1.2 of the HTTP specification](http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html). In most cases it will be a relative URI.
+
+*Please note that the domain/port that the client connects to is determined by `setPort` and `setHost`, and is not parsed from the uri.*
+
The return value from the appropriate request method is an `HttpClientRequest` object. You can use this to add headers to the request, and to write to the request body. The request object implements `WriteStream`.
Once you have finished with the request you must call the `end` method.
If you don't know the name of the request method in advance there is a general `request` method which takes the HTTP method as a parameter:
- client = Vertx::HttpClient.new
+ client = Vertx::HttpClient.new
+ client.host = 'foo.com'
- request = client.request('POST', 'http://localhost:8080/some-path/') do |resp|
+ request = client.request('POST', '/some-path/') do |resp|
puts "got response #{resp.status_code}"
end
@@ -1514,9 +1524,10 @@ If you don't know the name of the request method in advance there is a general `
There is also a method called `get_now` which does the same as `get`, but automatically ends the request. This is useful for simple GETs which don't have a request body:
- client = Vertx::HttpClient.new
+ client = Vertx::HttpClient.new
+ client.host = 'foo.com'
- client.get_now('http://localhost:8080/some-path/') do |resp|
+ client.get_now('/some-path/') do |resp|
puts "got response #{resp.status_code}"
end
@@ -1571,8 +1582,9 @@ The method can also be called with a string or Buffer in the same way write is c
To write headers to the request, add them to the Hash returned from the `headers` method:
client = Vertx::HttpClient.new
+ client.host = 'foo.com'
- request = client.post('http://localhost:8080/some-path') do |resp|
+ request = client.post('/some-path') do |resp|
puts "got response #{resp.status_code}"
end
@@ -1582,8 +1594,9 @@ To write headers to the request, add them to the Hash returned from the `headers
You can also use the `put_header` method to enable a more fluent API:
client = Vertx::HttpClient.new
+ client.host = 'foo.com'
- request = client.post('http://localhost:8080/some-path') do |resp|
+ request = client.post('/some-path') do |resp|
puts "got response #{resp.status_code}"
end.put_header('Some-Header', 'Some-Value').
put_header('Some-Other-Header', 'Some-Other-Value').
@@ -1608,8 +1621,9 @@ The response object implements `ReadStream`, so it can be pumped to a `WriteStre
To query the status code of the response use the `status_code` property. The `status_message` property contains the status message. For example:
client = Vertx::HttpClient.new
+ client.host = 'foo.com'
- client.get_now('http://localhost:8080/some-path') do |resp|
+ client.get_now('/some-path') do |resp|
puts "server returned status code: #{resp.status_code}"
puts "server returned status message: #{resp.status_message}"
end
@@ -1624,8 +1638,9 @@ To receive the response body, you set a `dataHandler` on the response object whi
client = Vertx::HttpClient.new
+ client.host = 'foo.com'
- client.get_now('http://localhost:8080/some-path') do |resp|
+ client.get_now('/some-path') do |resp|
resp.data_handler { |buffer| puts "I received #{buffer.length} bytes" }
end
@@ -1637,8 +1652,9 @@ The `data_handler` can be called multiple times for a single HTTP response.
As with a server request, if you wanted to read the entire response body before doing something with it you could do something like the following:
client = Vertx::HttpClient.new
+ client.host = 'foo.com'
- client.get_now('http://localhost:8080/some-path') do |resp|
+ client.get_now('/some-path') do |resp|
# Create a buffer to hold the entire response body
body = Vertx::Buffer.create(0)
@@ -1668,8 +1684,9 @@ The body handler is called only once when the *entire* response body has been re
Here's an example using `body_handler`:
client = Vertx::HttpClient.new
+ client.host = 'foo.com'
- client.get_now('http://localhost:8080/some-path') do |resp|
+ client.get_now('/some-path') do |resp|
resp.body_handler do |body|
puts "The total body received was #{body.length} bytes"
@@ -1696,8 +1713,9 @@ This is used in conjunction with the `send_head` function to send the head of th
An example will illustrate this:
client = Vertx::HttpClient.new
+ client.host = 'foo.com'
- request = client.put('http://localhost:8080/some-path') do |resp|
+ request = client.put('/some-path') do |resp|
puts "Got a response: #{resp.status_code}"

0 comments on commit 47c3f4b

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