Chapter 07 RESTful api call with HTTP
Chapter 07 RESTful api call with HTTP
WITH HTTP
I CT425 MOBILE APPLICATION DEVELOPMENT
PRASHAYA FUSI RIPONG (PH.D.)
1. What is Asynchronous
Programming?
2. Why asynchronous code
matters?
OUTLINE 3. Future, async and await
4. HTTP GET Request in Flutter
5. HTTP POST Request in Flutter
6. Handling Error
WHAT IS ASYNCHRONOUS PROGRAMMING?
• Asynchronous programming
paradigm allows certain tasks to run
separately from the ‘main’
execution thread
The programs allowing your
application to continue executing
other tasks while waiting for the
asynchronous operation to finish
Asynchronous
- Operation: Once initiated, an asynchronous operation allows other operations to execute before
it completes
- Function: An asynchronous function performs at least one asynchronous operation and can also
perform synchronous operations
FUTURE, ASYNC AND AWAIT
• Future is an object that represents the result of an asynchronous operation and
can have two states: uncompleted or completed
Then() returns the final result from the Future<TYPE> of Flutter, here <TYPE> means the
data type you want to return from the Future
catchError() UnCompleted or error data - do task when you didn’t able to get the
data or error occured
whenComplete() Executes on, either way, weather data was return or error was
thrown. Its used when you want to perform something in either case happens
• Await will wait for a future to complete before executing the subsequence
statement
CALLING DATA FROM SERVER REST API
CALLING DATA FROM SERVER REST API
• Dio package
A powerful HTTP networking package for Dart/Flutter, supports Global configuration,
Interceptors, FormData, Request cancellation, File uploading/downloading, Timeout,
Custom adapters, Transformers, etc.
• Data format that use on the openweather API as Json data format
Thank you
Prashaya Fusiripong (Ph.D.)
Email: [email protected]
Department of Information and communication technology (ICT), International college