open weather map http get code example

Example 1: open weather map http get

// include http dependency in pubspec.yaml
/*
 * https://pub.dev/packages/http/install
 * */
dependencies:
  http: ^0.13.1
    
// import http in the dart file where you will be interacting with it
import 'package:http/http.dart' as http;

// use http
/*
 * you will get your {key} from https://openweathermap.org/
 write the key without the braces {}
 
 if you run into any Uri issues: https://stackoverflow.com/questions/55995791/how-can-i-resolve-the-argument-type-string-cant-be-assigned-to-the-parameter
 
 * */

String url =
      'https://api.openweathermap.org/data/2.5/weather?lat=35&lon=139&appid={key}';
  Future getData() async {
    var response =
        await http.get(Uri.parse(url), headers: {"Accept": "application/json"});
    print(response.body);

    return "Success";
  }

Example 2: open weather map http get

// include http dependency in pubspec.yaml
/*
 * https://pub.dev/packages/http/install
 * */
dependencies:
  http: ^0.13.1
    
// import http in the dart file where you will be interacting with it
import 'package:http/http.dart' as http;

// use http
/*
 * you will get your {key} from https://openweathermap.org/
 write the key without the braces {}
 
 if you run into any Uri issues: https://stackoverflow.com/questions/55995791/how-can-i-resolve-the-argument-type-string-cant-be-assigned-to-the-parameter
 
 * */

String url =
      'https://api.openweathermap.org/data/2.5/weather?lat=35&lon=139&appid={key}';
  Future getData() async {
    var response =
        await http.get(Uri.parse(url), headers: {"Accept": "application/json"});
    print(response.body);

    return "Success";
  }


//How to start to work with Openweather API - OpenWeatherMaphttps://openweathermap.org › appid

Tags:

Misc Example