concept HttpRequest in category java

appears as: HttpRequest, HttpRequest
JavaFX in Action

This is an excerpt from Manning's book JavaFX in Action.

At the heart of JavaFX’s web service support are three classes. In the javafx.io.http package there’s the HttpRequest class, used to make the HTTP request; in javafx.data.pull there’s PullParser and Event, used to parse the reply.

Our application also uses three classes itself: FlickrService handles the request (using HttpRequest), FlickrResult processes the result (using PullParser and Event), and FlickrPhoto stores the details of the photos as they are pulled from the result.

After the argument list we have the HttpRequest object itself. The HTTP request doesn’t execute immediately. Web service requests are commonly instigated from inside UI event handlers; if we performed the request immediately, it would hog the current thread (the GUI thread) and cause our application’s interface to become temporarily unresponsive. Instead, when start() is called, the network activity is pushed onto another thread, and we assign callbacks to run when there’s something ready to act upon (see figure 8.2).

Figure 8.2. When start() is called on an HttpRequest object, a second thread takes over and communicates its progress through callback events, allowing the GUI thread to get back to its work.

The HttpRequest request declaratively sets a number of properties. The method and location variables tell HttpRequest how and where to direct the HTTP call. To form the web address we use the script function createArgList(), turning the args sequence into a web-like query string, and append it to the REST base URL. The onResponseCode, onException, and onInput event function types will be called at different stages of the request life cycle. The HttpRequest class actually has a host of different functions and variables to track the request state in fine detail (check the API docs), but typically we don’t need such fine-grained control.

sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest