Home

Awesome

akka-http-circe-json-template

Build Status License

REST API Project Template using Akka HTTP 10.0.4 with Circe 0.7.0 targeting Scala 2.12.x.

This project template proudly uses:

Usage

Start services with sbt:

$ sbt
> run

You can send requests to the following paths:

$ curl http://localhost:8000/api/v1/service1/status
$ curl http://localhost:8000/api/v1/service1/models/<int>
$ curl http://localhost:8000/api/v1/service1/modelsByName/<string>
$ curl -X POST -H 'Content-Type: application/json' http://localhost:8000/api/v2/service1/model -d 
    '{
        "vString": "akka-http-circe",
        "vInt":42, 
        "vLong":100000000,
        "vFloat":2.4,
        "vDouble":4.2,
        "vSeqInt":[1,2,3],
        "vListInt":[4,5,6]
     }'

The routes with logging enabled are under the /v2/ path as below:

$ curl http://localhost:8000/api/v2/service1/status
$ curl http://localhost:8000/api/v2/service1/models/<int>
$ curl http://localhost:8000/api/v2/service1/modelsByName/<string>
$ curl -X POST -H 'Content-Type: application/json' http://localhost:8000/api/v2/service1/model -d 
    '{
        "vString": "akka-http-circe",
        "vInt":42, 
        "vLong":100000000,
        "vFloat":2.4,
        "vDouble":4.2,
        "vSeqInt":[1,2,3],
        "vListInt":[4,5,6]
     }'

You will be able to see in the console the requests reaching the /v2/ as below:

Thread:[akka-http-circe-json-akka.actor.default-dispatcher-16] DEBUG akka.actor.ActorSystemImpl - log-service: Response for
Request : HttpRequest(HttpMethod(POST),http://localhost:8000/api/v2/service1/model,List(Host: localhost:8000, User-Agent: curl/7.51.0, Accept: */*, Timeout-Access: <function1>),
HttpEntity.Strict(application/json,{"vString": "akka-http-circe", "vInt":42, "vLong":100000000, "vFloat":2.4,"vDouble":4.2,"vSeqInt":[1,2,3],"vListInt":[4,5,6]}),HttpProtocol(HTTP/1.1))
Response: Complete(HttpResponse(200 OK,List(),HttpEntity.Strict(application/json,{"message":"model.vString: akka-http-circe - model.vListInt: List(4, 5, 6)"}),HttpProtocol(HTTP/1.1)))

License

This code is open source software licensed under the Apache 2.0 License.