This repository was archived by the owner on Dec 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
REST API
Arsene edited this page Sep 10, 2020
·
2 revisions
To implement a REST API you will need to define a service definition and implement that service definition.
This helps interact with both the Write Side and the Read Side.
- To define the service definition you will extend the following trait:
io.superflat.lagompb.BaseService.
Example:
trait AccountService extends BaseService {
def openAccount: ServiceCall[OpenAccountRequest, ApiResponse]
def transferMoney(accountId: String): ServiceCall[TransferMoneyRequest, ApiResponse]
def receiveMoney(accountId: String): ServiceCall[ReceiveMoneyRequest, ApiResponse]
def getAccount(accountId: String): ServiceCall[NotUsed, ApiResponse]
override val routes: Seq[Descriptor.Call[_, _]] = Seq(
restCall(Method.POST, "/api/accounts", openAccount _),
restCall(Method.PATCH, "/api/accounts/:accountId/transfer", transferMoney _),
restCall(Method.PATCH, "/api/accounts/:accountId/receive", receiveMoney _),
restCall(Method.GET, "/api/accounts/:accountId", getAccount _)
)
}- Then you implement the service definition by extending the following abstract class
io.superflat.lagompb.BaseServiceImplmixed in with the previous service definition defined.
Example:
class AccountServiceImpl(
clusterSharding: ClusterSharding,
persistentEntityRegistry: PersistentEntityRegistry,
aggregate: AggregateRoot
)(implicit ec: ExecutionContext)
extends BaseServiceImpl(clusterSharding, persistentEntityRegistry, aggregate){
// your implementation goes in here
}Copyright © 2020 superflat