BuscaCEP is a library for consulting online addresses, allowing searches by CEP (Postal Address Code) or by street (UF, Locality and Street).
Implemented in the Delphi
language, it uses the concept of a fluent interface to guide the use of the library, developed to offer practicality and efficiency, BuscaCEP integrates the main players in the market: Correios, ViaCEP, BrasilAPI, among others.
This library is ideal for Delphi developers looking for a robust, flexible and efficient solution to integrate online address queries into their applications.
Using Boss (Dependency manager for Delphi) it is possible to install the library in an automated way.
boss install https://github.com/antoniojmsjr/BuscaCEP
If you choose to install manually, simply add the following folders to your project, under Project > Options > Delphi Compiler > Target > All Configurations > Search path
.. BuscaCEP Source
Provider | Do you use APIKey? | Search by zip code? | * Search for Public Place? |
---|---|---|---|
NO | YES | YES | |
Via CEP | NO | YES | YES |
Brazil API | NO | YES | NO |
Open CEP | YES | YES | YES |
Virtual Republic | NO | YES | NO |
Correct zip code | NO | YES | YES |
KingHost | YES | YES | NO |
Postmon | NO | YES | NO |
Free CEP | YES | YES | YES |
Open CEP | YES | YES | YES |
CEP API | YES | YES | YES |
Brazil Open | YES | YES | YES |
AwesomeAPI | NO | YES | NO |
* To query using the street address, three mandatory parameters are required: State, City and Street .
To provide the IBGE code and DDD code for the location when returning the query, the BuscaCEP .dat file was created, based on the IBGE location API and data provided by Anatel.
Examples are available in the project folder:
.. BuscaCEP Samples
Query by zip code
uses
BuscaCEP , BuscaCEP .Types, BuscaCEP .Interfaces, System.SysUtils;
var
l BuscaCEP Response: I BuscaCEP Response;
lMsgError: string;
begin
try
l BuscaCEP Response := T BuscaCEP .New
// .SetArquivoCache() [OPCIONAL]
.Providers[T BuscaCEP ProvidersKind.Correios]
// .SetAPIKey() [CONFORME O PROVEDOR]
.Filtro
.SetCEP( ' 90520-003 ' )
.Request
// .SetTimeout() [OPCIONAL]
.Execute;
except
on E: E BuscaCEP Request do
begin
lMsgError := Concat(lMsgError, Format( ' Provider: %s ' , [E.Provider]), sLineBreak);
lMsgError := Concat(lMsgError, Format( ' DateTime: %s ' , [DateTimeTostr(E.DateTime)]), sLineBreak);
lMsgError := Concat(lMsgError, Format( ' Kind: %s ' , [E.Kind.AsString]), sLineBreak);
lMsgError := Concat(lMsgError, Format( ' URL: %s ' , [E.URL]), sLineBreak);
lMsgError := Concat(lMsgError, Format( ' Method: %s ' , [E.Method]), sLineBreak);
lMsgError := Concat(lMsgError, Format( ' Status Code: %d ' , [E.StatusCode]), sLineBreak);
lMsgError := Concat(lMsgError, Format( ' Status Text: %s ' , [E.StatusText]), sLineBreak);
lMsgError := Concat(lMsgError, Format( ' Message: %s ' , [E.Message]));
Application.MessageBox(PWideChar(lMsgError), ' A T E N Ç Ã O ' , MB_OK + MB_ICONERROR);
Exit;
end ;
on E: Exception do
begin
Application.MessageBox(PWideChar(E.Message), ' A T E N Ç Ã O ' , MB_OK + MB_ICONERROR);
Exit;
end ;
end ;
end ;
Consultation by Street
uses
BuscaCEP , BuscaCEP .Types, BuscaCEP .Interfaces, System.SysUtils;
var
l BuscaCEP Response: I BuscaCEP Response;
lMsgError: string;
begin
try
l BuscaCEP Response := T BuscaCEP .New
// .SetArquivoCache() [OPCIONAL]
.Providers[T BuscaCEP ProvidersKind.Correios]
// .SetAPIKey() [CONFORME O PROVEDOR]
.Filtro
.SetLogradouro( ' Avenida Plínio Brasil Milano ' )
.SetLocalidade( ' Porto Alegre ' )
.SetUF( ' RS ' )
.& End
.Request
// .SetTimeout() [OPCIONAL]
.Execute;
except
on E: E BuscaCEP Request do
begin
lMsgError := Concat(lMsgError, Format( ' Provider: %s ' , [E.Provider]), sLineBreak);
lMsgError := Concat(lMsgError, Format( ' DateTime: %s ' , [DateTimeTostr(E.DateTime)]), sLineBreak);
lMsgError := Concat(lMsgError, Format( ' Kind: %s ' , [E.Kind.AsString]), sLineBreak);
lMsgError := Concat(lMsgError, Format( ' URL: %s ' , [E.URL]), sLineBreak);
lMsgError := Concat(lMsgError, Format( ' Method: %s ' , [E.Method]), sLineBreak);
lMsgError := Concat(lMsgError, Format( ' Status Code: %d ' , [E.StatusCode]), sLineBreak);
lMsgError := Concat(lMsgError, Format( ' Status Text: %s ' , [E.StatusText]), sLineBreak);
lMsgError := Concat(lMsgError, Format( ' Message: %s ' , [E.Message]));
Application.MessageBox(PWideChar(lMsgError), ' A T E N Ç Ã O ' , MB_OK + MB_ICONERROR);
Exit;
end ;
on E: Exception do
begin
Application.MessageBox(PWideChar(E.Message), ' A T E N Ç Ã O ' , MB_OK + MB_ICONERROR);
Exit;
end ;
end ;
end ;
Query Result [I BuscaCEP Response]
uses
BuscaCEP .Types, BuscaCEP .Interfaces;
var
l BuscaCEP Response: I BuscaCEP Response;
l BuscaCEP Logradouro: T BuscaCEP Logradouro;
begin
for l BuscaCEP Logradouro in l BuscaCEP Response.Logradouros do
begin
l BuscaCEP Logradouro.Logradouro;
l BuscaCEP Logradouro.Complemento;
l BuscaCEP Logradouro.Unidade;
l BuscaCEP Logradouro.Bairro;
l BuscaCEP Logradouro.Localidade.Nome;
l BuscaCEP Logradouro.Localidade.IBGE;
l BuscaCEP Logradouro.Localidade.DDD;
l BuscaCEP Logradouro.Localidade.Estado.Nome;
l BuscaCEP Logradouro.Localidade.Estado.IBGE;
l BuscaCEP Logradouro.Localidade.Estado.Sigla;
l BuscaCEP Logradouro.Localidade.Estado.Regiao.Nome;
l BuscaCEP Logradouro.Localidade.Estado.Regiao.IBGE;
l BuscaCEP Logradouro.Localidade.Estado.Regiao.Sigla;
l BuscaCEP Logradouro.CEP;
end ;
Query Result [JSON]
{
"provider" : " #CORREIOS " ,
"date_time" : " 2024-05-01T02:35:14.772-03:00 " ,
"request_time" : " 75ms " ,
"total" : 1 ,
"logradouros" : [
{
"logradouro" : " Avenida Plínio Brasil Milano " ,
"complemento" : " de 1947 ao fim - lado ímpar " ,
"unidade" : " " ,
"bairro" : " Passo da Areia " ,
"cep" : " 90520003 " ,
"localidade" : {
"ibge" : 4314902 ,
"ddd" : 51 ,
"nome" : " Porto Alegre " ,
"estado" : {
"ibge" : 43 ,
"nome" : " Rio Grande do Sul " ,
"sigla" : " RS " ,
"regiao" : {
"ibge" : 4 ,
"nome" : " Sul " ,
"sigla" : " S "
}
}
}
}
]
}
Download: Demos.zip
BuscaCEP
is free and open-source software licensed under the