0

I have went through 2 examples of using Lagom to develop Micro-Service Architecture system, namely the 'chirp' and 'cargotracker', but none of them show how to update to existing entity.

For instance, having following entity with REST URI

Sugguestion{ id content viewCount author }

api/suggestion      with  Http Post      ----> add a new suggestion
api/suggestion/:id  with Http Get,       ---->read a suggestion
api/suggestion/:id  with Http Delete,   ---->remove a suggestion

How about update ?

1)api/suggestion/viewCount with Http Put?

2)api/suggestion/:id with Http Put ?

3)api/suggestion/:id with Http Post ?

There are some disadvantages of the above 3 approch

for 1), need to define a seperately data class for each fields, otherwise, update directly on the Suggestion entity would introduce 'mutable changes', which is aginst the principle of Lagom.

for 2)&3), need a deep copy of the old state and update with changed fields, otherwise, introduces 'mutable changes' as well.

Is there any other options ?

Thanks

Bond Chen
  • 168
  • 1
  • 8

1 Answers1

0

We use something like

api/suggestion/:id PUT     // for updating the entire resource
api/suggestion/:id/views   //for updating a portion of the resource

1) the services map requests to commands. the command can simply contain a subset of the fields in the entity. 2) and 3) you need to read the docs and CQRS design. The architecture is foremost for dealing with highly concurrent updates to mutable state

dres
  • 1,172
  • 11
  • 15