Java Reference
In-Depth Information
For every question that is in the items of the ListView , the output is now what we expected it to be. We can
do a lot more with CellFactories (e.g., we can use graphics instead of just text), but that is beyond the scope of
this chapter.
We now replace the hard-coded questions with real information obtained via the StackExchange API.
Using the StackExchange API
The Stack Exchange Network ( http://stackexchange.com ) allows third-party developers to browse and access
questions and answers using a REST-based interface. StackExchange maintains a number of REST-based APIs, but
for our examples we limit ourselves to the Search API. Detailed information on the Search API is obtained from
http://api.stackexchange.com/docs .
The resource URL—the endpoint for the REST service—is very simple:
http://api.stackexchange.com/2.2/search
A number of query parameters can be supplied here. We will only use two parameters, and the interested reader
is referred to the StackExchange documentation for information about the other parameters.;
Site: Specify the domain you want to search, in our case this is “stackoverflow.”
tagged: A semicolon delimited list of tags. We want to search all questions tagged with “javafx.”
Combining both parameters leads to the following REST call:
http://api.stackexchange.com/2.2/search?tagged=javafx&site=stackoverflow
When executing this REST call in a browser, or using a command tool (e.g., curl), the result is something like the
JSON-text in Listing 11-5.
Listing 11-5. JSON Response Obtained from the StackExchange Search API
{
"items": [
{
"tags": [
"java",
"sorting",
"javafx",
"tableview"
],
"owner": {
"reputation": 132,
"user_id": 578518 ,
"user_type": "registered",
"accept_rate": 84,
"profile_image": "https://www.gravatar.com/avatar/bdbee99c377a7063b24e09e7121fb1ab?s=128&d=
identicon&r=PG" ,
"display_name": "Rps",
"link": "http://stackoverflow.com/users/578518/rps"
},
"is_answered": false,
"view_count": 7,
 
Search WWH ::




Custom Search