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
The resource URL—the endpoint for the REST service—is very simple:
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:
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_type": "registered",
"accept_rate": 84,
"display_name": "Rps",
},
"is_answered": false,
"view_count": 7,
Search WWH ::
Custom Search