Code Monkey home page Code Monkey logo

geolocationapi's Introduction

GeoLocationAPI

.NET Web API for retrieving geolocations. Geolocation data provided by MaxMind GeoLite2.

Prerequisites

To get started you will need:

Running Locally

To get started, simply run the application in an IDE such as Visual Studio or issue the following command from the root of the project:

dotnet run --project GeoLocationAPI/GeoLocationAPI.csproj

Sample URL's:

You can also run the project in Docker by running:

docker-compose -f docker-compose.yml -f docker-compose.development.yml up

Once the container is up and running you can simply do something like this:

curl -X GET "http://localhost:5254/api/v1/GeoLocation/71.168.176.139" -v

Sample Payload:

{
	"date": "2021-08-12T13:45:02.2587451Z",
	"ipAddress": "71.168.176.139",
	"city": "Trenton",
	"timeZone": "America/New_York",
	"continent": "North America",
	"country": "United States",
	"ipFoundInGeoDB": true,
	"message": "71.168.176.139 found in the GeoDB"
}

You can check the healthcheck by issuing something like this. Note that it will return ProcessArchitecture which is useful to see if the workload is running on Arm64 or X64. The HealtcheckIPToTest (in this case 8.8.8.8) is set in the appsettings.json files:

curl -X GET "http://localhost:5254/hc" -v

Sample Payload:

{
	"Status": "Healthy",
	"Duration": "00:00:00.0084379",
	"FrameworkDescription": ".NET 6.0.12",
	"ProcessArchitecture": "Arm64",
	"Results": {
		"GeoLocationHealthCheck": {
			"Status": "Healthy",
			"Description": "The healthcheck is healthy - 8.8.8.8 found in the GeoDB",
			"Data": {}
		}
	}
}

Running on ECS Fargate

The AWS CDK is used to deploy the application to ECS Fargate and is protected with AWS WAF via the CDK for C#. Follow the instructions in the README.md.

Alternatively, you can use the Docker Compose for Amazon ECS integration to launch the application to ECS Fargate by using the Docker CLI. You can look at docker-compose-ecs-demo.yml to see a simple example. Note: the GeoLocationAPI project uses OpenTelemetry and since the Docker Compose for Amazon ECS integration currently doesn't support creating sidecars in the task definition, this simple example doesn't showcase the aws-otel-collector. To see that functionality, deploy with the CDK instead as mentioned above in the README.md.

Running on Kubernetes

To deploy to an existing Kubernetes cluster:

kubectl apply -f templates/

The geolocationapi.yaml manifest doesn't expose the service via a load balancer so in order to test do something like this:

kubectl exec -it busybox -n default -- wget -qO- http://{Service-IP}:{Port}/api/v1/geolocation/8.8.8.8

geolocationapi's People

Contributors

carmenapuccio avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.