Created
September 11, 2019 20:05
-
-
Save kleberandrade/756afbcdaa9f80e54760f02e2f07d24c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:http/http.dart' as http; | |
import 'package:search_cep/models/result_cep.dart'; | |
class ViaCepService { | |
static Future<ResultCep> fetchCep({String cep}) async { | |
final response = await http.get('https://viacep.com.br/ws/$cep/json/'); | |
if (response.statusCode == 200) { | |
return ResultCep.fromJson(response.body); | |
} else { | |
throw Exception('Requisição inválida!'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment