Skip to content

Commit

Permalink
Merge pull request #27 from guibranco/develop
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
guibranco committed Mar 29, 2020
2 parents 171fdb1 + 9a6b1b0 commit 0da74c7
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,25 @@ The package has two classes:

This package is fully compatible with Dependency Injection. Use the interface *IViaCepClient* and the constructor with HttpClient parameter with a IHttpClientFactory instance.

```
```cs
//your DI container
services.AddHttpClient<IViaCepClient, ViaCepClient>(client =>{
services.AddHttpClient<IViaCepClient, ViaCepClient>(client => {
client.BaseAddress = new Uri("https://viacep.com.br/");
})
});

//then use in your domain service, handler, controller...
var viaCepClient = container.GetService<IViaCepClient>();
var result = await viaCepClient.SearchAsync("01001000", cancellationToken);
```

You can search using the zip code/postal code (AKA CEP) or using the address data (state initials - UF, city name and location name - street, avenue, park, square). Both methods support async and sync!

## Querying by zip code / postal code (single result)

```cs
var result = new ViaCepClient().Search("01234567"); //searches for the postal code 01234-567
var address = result.Address;
var neighborhood = result.Neighborhood
var result = new ViaCepClient().Search("01001000"); //searches for the postal code 01001-000
var address = result.Address; //Praça da Sé
var city = reuslt.City; //São Paulo
//do what you need with 'result' instance of ViaCEPResult.
```

Expand Down

0 comments on commit 0da74c7

Please sign in to comment.