Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/digillect/dadata

DaData.ru client for .NET Standard
https://github.com/digillect/dadata

Last synced: 15 days ago
JSON representation

DaData.ru client for .NET Standard

Awesome Lists containing this project

README

        

# Digillect DaData.ru client

Implementation of the [DaData](https://dadata.ru/) features, based on HTTP Client through Refit.

## Available features

- [Address suggestions](https://dadata.ru/api/suggest/address/)
- [Address by FIAS/KLADR identifier](https://dadata.ru/api/find-address/)
- [City by IP address](https://dadata.ru/api/iplocate/)

## Usage

Register the client in DI container passing API key, if any:

```csharp
services.AddDaDataSuggestionsClient("123456");
```

Then inject the client into your services/controllers:

```csharp
[Route("/api/addresses")]
public sealed class AddressesController : ApiController
{
private readonly IDaDataSuggestionsClient _client;

public AddressesController(IDaDataSuggestionsClient client)
{
_client = client;
}

///
/// Suggests addresses for the specified query.
///
[HttpGet("suggestions")]
public Task> GetSuggestionsAsync(string query) => _client.SuggestAddressAsync(query);

///
/// Suggests cities for the specified query.
///
[HttpGet("cities")]
public async Task> GetCitiesAsync(string query)
{
var request = SuggestAddressRequest.Create(query).From(SuggestAddressBound.City).To(SuggestAddressBound.City);
var response = await _client.SuggestAddressAsync(request);

return response.Suggestions;
}
}
```