Skip to content

Instantly share code, notes, and snippets.

@kleberandrade
Created September 11, 2019 20:05
Show Gist options
  • Save kleberandrade/756afbcdaa9f80e54760f02e2f07d24c to your computer and use it in GitHub Desktop.
Save kleberandrade/756afbcdaa9f80e54760f02e2f07d24c to your computer and use it in GitHub Desktop.
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