<commit_before># GeoIP2 .NET API #

[![Windows CI](https://ci.appveyor.com/api/projects/status/github/maxmind/GeoIP2-dotnet?svg=true)](https://ci.appveyor.com/project/maxmind/GeoIP2-dotnet/branch/master "Appveyor CI")
[![Unix CI](https://travis-ci.org/maxmind/GeoIP2-dotnet.svg?branch=master)](https://travis-ci.org/maxmind/GeoIP2-dotnet "Travis CI")

## Description ##

This distribution provides an API for the GeoIP2
[web services](https://dev.maxmind.com/geoip/geoip2/web-services) and
[databases](https://dev.maxmind.com/geoip/geoip2/downloadable). The API also
works with the free [GeoLite2 databases](https://dev.maxmind.com/geoip/geoip2/geolite2/).

## Requirements ##

This library works with .NET Framework version 4.5 and above and .NET Standard 1.4 or
above. If you are using Mono, 3.2 or greater is required.

This library depends on
[MaxMind DB Reader](https://github.com/maxmind/MaxMind-DB-Reader-dotnet).

## Installation ##

### NuGet ###

We recommend installing this library with NuGet. To do this, type the
following into the Visual Studio Package Manager Console:

```
install-package MaxMind.GeoIP2
```

## IP Geolocation Usage ##

IP geolocation is inherently imprecise. Locations are often near the center of
the population. Any location provided by a GeoIP2 database or web service
should not be used to identify a particular address or household.

## Web Service Usage ##

To use the web service API, first create a new `WebServiceClient` object
with your account ID and license key:

```
var client = new WebServiceClient(42, "license_key1");
```

You may also specify the fall-back locales, the host, or the timeout as
optional parameters. See the API docs for more information.

This object is safe to share across threads. If you are making multiple
requests, the object should be reused to so that new connections are not
created for each request. Once you have finished making requests, you
should dispose of the object to ensure the connections are closed and any
resources are promptly returned to the system.

You may then call the sync or async method corresponding to the specific end
point, passing it the IP address you want to look up or no parameters if you
want to look up the current device.

If the request succeeds, the method call will return a response class for the
endpoint you called. This response in turn contains multiple model classes,
each of which represents part of the data returned by the web service.

See the API documentation for more details.

### ASP.NET Core Usage ###

To use the web service API with HttpClient factory pattern as a [Typed client](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-3.1#typed-clients)
you need to do the following:

1. Add the following lines to ```Startup.cs``` ```ConfigureServices``` method:

```csharp
services.Configure<WebServiceClientOptions>(Configuration.GetSection("MaxMind")); // Configure to read configuration options from MaxMind section

services.AddHttpClient<WebServiceClient>(); // Configure dependency injection for WebServiceClient
```

2. Add configuration in your ```appsettings.json``` with your account ID and license key.

```json
...
  "MaxMind": {
    "AccountId": 123456,
    "LicenseKey": "1234567890",
    "Timeout": 3000, // optional
    "Host": "geoip.maxmind.com" // optional
  },
...
```

3. Inject the ```WebServiceClient``` where you need to make the call and use it.<commit_msg>Switched to jsonc to support comments for JSON in README.md.<commit_after># GeoIP2 .NET API #

[![Windows CI](https://ci.appveyor.com/api/projects/status/github/maxmind/GeoIP2-dotnet?svg=true)](https://ci.appveyor.com/project/maxmind/GeoIP2-dotnet/branch/master "Appveyor CI")
[![Unix CI](https://travis-ci.org/maxmind/GeoIP2-dotnet.svg?branch=master)](https://travis-ci.org/maxmind/GeoIP2-dotnet "Travis CI")

## Description ##

This distribution provides an API for the GeoIP2
[web services](https://dev.maxmind.com/geoip/geoip2/web-services) and
[databases](https://dev.maxmind.com/geoip/geoip2/downloadable). The API also
works with the free [GeoLite2 databases](https://dev.maxmind.com/geoip/geoip2/geolite2/).

## Requirements ##

This library works with .NET Framework version 4.5 and above and .NET Standard 1.4 or
above. If you are using Mono, 3.2 or greater is required.

This library depends on
[MaxMind DB Reader](https://github.com/maxmind/MaxMind-DB-Reader-dotnet).

## Installation ##

### NuGet ###

We recommend installing this library with NuGet. To do this, type the
following into the Visual Studio Package Manager Console:

```
install-package MaxMind.GeoIP2
```

## IP Geolocation Usage ##

IP geolocation is inherently imprecise. Locations are often near the center of
the population. Any location provided by a GeoIP2 database or web service
should not be used to identify a particular address or household.

## Web Service Usage ##

To use the web service API, first create a new `WebServiceClient` object
with your account ID and license key:

```
var client = new WebServiceClient(42, "license_key1");
```

You may also specify the fall-back locales, the host, or the timeout as
optional parameters. See the API docs for more information.

This object is safe to share across threads. If you are making multiple
requests, the object should be reused to so that new connections are not
created for each request. Once you have finished making requests, you
should dispose of the object to ensure the connections are closed and any
resources are promptly returned to the system.

You may then call the sync or async method corresponding to the specific end
point, passing it the IP address you want to look up or no parameters if you
want to look up the current device.

If the request succeeds, the method call will return a response class for the
endpoint you called. This response in turn contains multiple model classes,
each of which represents part of the data returned by the web service.

See the API documentation for more details.

### ASP.NET Core Usage ###

To use the web service API with HttpClient factory pattern as a [Typed client](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-3.1#typed-clients)
you need to do the following:

1. Add the following lines to ```Startup.cs``` ```ConfigureServices``` method:

```csharp
services.Configure<WebServiceClientOptions>(Configuration.GetSection("MaxMind")); // Configure to read configuration options from MaxMind section

services.AddHttpClient<WebServiceClient>(); // Configure dependency injection for WebServiceClient
```

2. Add configuration in your ```appsettings.json``` with your account ID and license key.

```jsonc
...
  "MaxMind": {
    "AccountId": 123456,
    "LicenseKey": "1234567890",
    "Timeout": 3000, // optional
    "Host": "geoip.maxmind.com" // optional
  },
...
```

3. Inject the ```WebServiceClient``` where you need to make the call and use it.
{'fraction_non_alphanumeric': 0.0981294964028777, 'fraction_numerical': 0.013525179856115108, 'mean_word_length': 4.578651685393258, 'pattern_counts': {'":': 10, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 18, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3449775', 'n_tokens_mistral': 2073, 'n_tokens_neox': 1962, 'n_words': 818}