Created
December 31, 2018 11:40
-
-
Save argentinaluiz/0df59e611c0a4f527605ea8f9b574bd0 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 { Injectable } from '@angular/core'; | |
| import {HttpClient} from "@angular/common/http"; | |
| import {Cep} from './cep'; | |
| import {map} from 'rxjs/operators'; | |
| @Injectable() | |
| export class CepService { | |
| constructor(private http:HttpClient) { } | |
| buscar(cep:string){ | |
| return this.http.get<any>(`https://viacep.com.br/ws/${cep}/json/`) | |
| .pipe( | |
| map(response => this.converterRespostaParaCep(response.data)) | |
| ); | |
| } | |
| private converterRespostaParaCep(cepNaResposta):Cep{ | |
| let cep = new Cep(); | |
| cep.cep = cepNaResposta.cep; | |
| cep.logradouro = cepNaResposta.logradouro; | |
| cep.complemento = cepNaResposta.complemento; | |
| cep.bairro = cepNaResposta.bairro; | |
| cep.cidade = cepNaResposta.localidade; | |
| cep.estado = cepNaResposta.uf; | |
| return cep; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment