Skip to content

Instantly share code, notes, and snippets.

@erangaeb
Created January 31, 2016 08:28
Show Gist options
  • Save erangaeb/bbfea506f956fc9d813f to your computer and use it in GitHub Desktop.
Save erangaeb/bbfea506f956fc9d813f to your computer and use it in GitHub Desktop.
Spray based Employee Service implementation
trait SprayEmployeeServiceCompImpl extends EmployeeServiceComp with Configuration {
this: CakezActorSystem =>
val employeeService = new SprayEmployeeService
class SprayEmployeeService extends EmployeeService {
def logger = LoggerFactory.getLogger(this.getClass)
override def POST(employee: Employee): Future[Unit] = {
import system.dispatcher
import com.pagero.cakez.protocols.EmployeeProtocol._
logger.debug(s"POST employee with id: ${employee.emp_id} name: ${employee.name}")
val pipeline = sendReceive
val response = pipeline {
Post(s"http://$apiHost:$apiPort/api/v1/users/", employee)
}
response.map(_.entity.asInstanceOf[Unit])
}
override def GET(id: Int): Future[Employee] = {
import system.dispatcher
import com.pagero.cakez.protocols.EmployeeProtocol._
logger.debug("GET employee with id: " + id)
val pipeline = sendReceive ~> unmarshal[Employee]
val response: Future[Employee] = pipeline {
Get(s"http://$apiHost:$apiPort/api/v1/users/$id/?format=json")
}
response
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment