OLD | NEW |
---|---|
1 --- | 1 --- |
2 layout: default | 2 layout: default |
3 title: "Fetch Data Dynamically" | 3 title: "Fetch Data Dynamically" |
4 description: "Use HttpRequest to fetch data from a file or a server." | 4 description: "Use HttpRequest to fetch data from a file or a server." |
5 has-permalinks: true | 5 has-permalinks: true |
6 tutorial: | 6 tutorial: |
7 id: fetchdata | 7 id: fetchdata |
8 next: forms/ | 8 next: forms/ |
9 next-title: "Get Input from a Form" | 9 next-title: "Get Input from a Form" |
10 prev: polymer-intro/ | 10 prev: futures/ |
11 prev-title: "Define a Custom Element" | 11 prev-title: "Use Future Based APIs" |
Kathy Walrath
2013/12/02 17:36:04
Global:
Future Based APIs -> Future-Based APIs
(
| |
12 --- | 12 --- |
13 | 13 |
14 {% capture whats_the_point %} | 14 {% capture whats_the_point %} |
15 | 15 |
16 * Data on the web is often formatted in JSON. | 16 * Data on the web is often formatted in JSON. |
17 * JSON is text based and human readable. | 17 * JSON is text based and human readable. |
18 * The dart:convert library provides support for JSON. | 18 * The dart:convert library provides support for JSON. |
19 * Use HttpRequest to dynamically load data. | 19 * Use HttpRequest to dynamically load data. |
20 | 20 |
21 {% endcapture %} | 21 {% endcapture %} |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 | 290 |
291 This program uses a convenience method, | 291 This program uses a convenience method, |
292 `getString()`, | 292 `getString()`, |
293 provided by the HttpRequest class | 293 provided by the HttpRequest class |
294 to request the file from the server. | 294 to request the file from the server. |
295 | 295 |
296 <img class="scale-img-max" src="images/getstringfunction.png" | 296 <img class="scale-img-max" src="images/getstringfunction.png" |
297 alt="Use the getString() function to make a request"> | 297 alt="Use the getString() function to make a request"> |
298 | 298 |
299 The getString() method uses a Future object to handle the request. | 299 The getString() method uses a Future object to handle the request. |
300 You can use the code above as an idiom | 300 A Future is a way to perform potentially time-consuming operations, |
301 such as HTTP requests, asynchronously. | |
302 If you haven't encountered Futures yet, | |
303 you can learn more about them in | |
304 [Use Future Based APIs](/docs/tutorials/futures/). | |
305 Until then, you can use the code above as an idiom | |
301 and provide your own code for the body of the processString() function | 306 and provide your own code for the body of the processString() function |
302 and your own code to handle the error. | 307 and your own code to handle the error. |
303 | 308 |
304 ###Using a relative URI | 309 ###Using a relative URI |
305 | 310 |
306 The URI used for the GET request specifies just the name of | 311 The URI used for the GET request specifies just the name of |
307 the portmanteaux_simple.json data file. | 312 the portmanteaux_simple.json data file. |
308 Let's take a look at how that works. | 313 Let's take a look at how that works. |
309 | 314 |
310 | 315 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 alt="Decode a JSON formatted list of strings"> | 460 alt="Decode a JSON formatted list of strings"> |
456 | 461 |
457 ##Other resources | 462 ##Other resources |
458 | 463 |
459 Check out Chris Buckett's article, | 464 Check out Chris Buckett's article, |
460 <a href="/articles/json-web-service/" | 465 <a href="/articles/json-web-service/" |
461 target="_blank">Using Dart with JSON Web Services</a>, | 466 target="_blank">Using Dart with JSON Web Services</a>, |
462 for more information and an example with source code for both | 467 for more information and an example with source code for both |
463 client and server programs. | 468 client and server programs. |
464 | 469 |
465 ##What Next? | 470 ##What Next? |
Kathy Walrath
2013/12/02 17:36:04
Next -> next
| |
466 | 471 |
467 The next tutorial, | 472 * If you skipped the previous tutorial, |
473 [Use Future Based APIs](/docs/tutorials/futures/), | |
474 we highly recommend that you go back and learn about Futures | |
475 before going any further. | |
476 | |
477 * The next tutorial, | |
468 [Get Input from a Form](/docs/tutorials/forms/), | 478 [Get Input from a Form](/docs/tutorials/forms/), |
469 contains a client/server example that | 479 contains a client/server example that |
470 shows you how to use a form to get data from the user, | 480 shows you how to use a form to get data from the user, |
471 and using JSON, send that form to a server, | 481 and using JSON, send that form to a server, |
472 and handle the server's response. | 482 and handle the server's response. |
473 | 483 |
474 {% endcapture %} | 484 {% endcapture %} |
475 | 485 |
476 {% include tutorial.html %} | 486 {% include tutorial.html %} |
OLD | NEW |