• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

theiterators/akka-http-microservice: Example of http (micro)service in Scala &am ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

theiterators/akka-http-microservice

开源软件地址:

https://github.com/theiterators/akka-http-microservice

开源编程语言:

Scala 99.3%

开源软件介绍:

Akka HTTP microservice example

Join the chat at https://gitter.im/theiterators/akka-http-microservice GitHub license Build Status

Hot update: it's now running on Scala 3!

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 ip-api which offers JSON IP and GeoIP REST API for free for non-commercial use.

If you want to read a more thorough explanation, check out tutorial.

Deploy to Heroku Gitpod Ready-to-Code

Usage

Start services with sbt:

$ sbt
> ~reStart

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

$ curl http://localhost:9000/ip/8.8.8.8
{
  "city": "Mountain View",
  "query": "8.8.8.8",
  "country": "United States",
  "lon": -122.0881,
  "lat": 37.3845
}
$ curl -X POST -H 'Content-Type: application/json' http://localhost:9000/ip -d '{"ip1": "8.8.8.8", "ip2": "93.184.216.34"}'
{
  "distance": 4347.624347494718,
  "ip1Info": {
    "city": "Mountain View",
    "query": "8.8.8.8",
    "country": "United States",
    "lon": -122.0881,
    "lat": 37.3845
  },
  "ip2Info": {
    "city": "Norwell",
    "query": "93.184.216.34",
    "country": "United States",
    "lon": -70.8228,
    "lat": 42.1508
  }
}

Testing

Execute tests using test command:

$ sbt
> test

Author & license

If you have any questions regarding this project, contact:

Łukasz Sowa [email protected] from Iterators.

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




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
jbittel/httpry: HTTP logging and information retrieval tool发布时间:2022-06-17
下一篇:
chronolaw/http_study: follow me to study http发布时间:2022-06-17
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap