akka-http-spray-json connects Akka HTTP routes to Spray JSON. It marshals Scala values into JSON responses and unmarshals JSON requests into domain objects through implicitly available formatters. section 11.1.5
A practical setup follows three steps:
- Use built-in formats for basic values such as String, Int, Option, and List. section 11.1.5
- Define jsonFormat2, jsonFormat1, or another formatter for case classes and nested values. section 11.1.5
Expose sharded cargo through HTTP
A route extracts entityId, kind, and size, creates Container.Cargo, and sends AddCargo to the sharding region. The response defines formats for Cargo and Cargos, then completes with the actor result. A POST adds cargo, while GET returns JSON such as {"cargos":[{"kind":"bigbag","size":4},{"kind":"sack","size":12}]}. For request bodies, entity(as[Container.Cargo]) uses the same formatter for unmarshalling. The example chooses tell for fast cargo submission and ask for querying the container state. section 11.1.6
