Skip to content

saosebastiao/project_tang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Akka HTTP microservice example

Join the chat at https://gitter.im/theiterators/akka-http-microservice

This project demonstrates the Akka HTTP library and Scala to write a simple REST (micro)service. The project shows the following tasks that are typical for most Akka HTTP-based projects:

  • starting standalone HTTP server,
  • handling file-based configuration,
  • logging,
  • routing,
  • deconstructing requests,
  • unmarshalling JSON entities to Scala's case classes,
  • marshaling Scala's case classes to JSON responses,
  • error handling,
  • issuing requests to external services,
  • testing with mocking of external services.

The service in the template provides two REST endpoints - one which gives GeoIP info for given IP and another for calculating geographical distance between given pair of IPs. The project uses the service Telize which offers JSON IP and GeoIP REST API for free.

Deploy to Heroku

Usage

Start services with sbt:

$ sbt
> ~re-start

With the service up, you can start sending HTTP requests:

$ curl http://localhost:9000/ip/8.8.8.8
{
  "city": "Mountain View",
  "ip": "8.8.8.8",
  "latitude": 37.386,
  "country": "United States",
  "longitude": -122.0838
}
$ curl -X POST -H 'Content-Type: application/json' http://localhost:9000/ip -d '{"ip1": "8.8.8.8", "ip2": "8.8.4.4"}'
{
  "distance": 2201.448386715217,
  "ip1Info": {
    "city": "Mountain View",
    "ip": "8.8.8.8",
    "latitude": 37.386,
    "country": "United States",
    "longitude": -122.0838
  },
  "ip2Info": {
    "ip": "8.8.4.4",
    "country": "United States",
    "latitude": 38.0,
    "longitude": -97.0
  }
}

Testing

Execute tests using test command:

$ sbt
> test

Author & license

If you have any questions regarding this project contact:

Łukasz Sowa lukasz@theiterators.com from Iterators.

For licensing info see LICENSE file in project's root directory.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published