Created
January 31, 2016 08:28
-
-
Save erangaeb/bbfea506f956fc9d813f to your computer and use it in GitHub Desktop.
Spray based Employee Service implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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