How do you handle API calls in Flutter?
Use the http or dio package.
Example using http:
Example using Dio (with headers):
Use the http or dio package.
Example using http:
final response = await http.get(Uri.parse('https://api.example.com/data')); if (response.statusCode == 200) { var data = jsonDecode(response.body); }
Example using Dio (with headers):
Dio dio = Dio(); Response response = await dio.post( 'https://api.example.com/upload', data: {'name': 'Ankur'}, options: Options(headers: {'Authorization': 'Bearer token'}), );
Comments
Post a Comment