Axon CQRS + REST

Hello,
how are you doing rest with axon cqrs?
I found this article where author is telling that he is sending informations about which command should be used in content-type attribute.
But I didn’t seen this before so I’m asking if you are generally creating RPCs ore use some other techniques.

Also are you exposing commands to the rest interface (for example are you putting CreateUserCommand to rest method createUser(CreateUserCommand command)) or are you using some DTOs?

Thanks

Generally, I see two approaches in the different projects that I have done or visited. The first is a traditional facade, where an application registers specific endpoints for the application’s actions. Each of these endpoints will translate the request to one (or more) queries and/or commands.
The other is a more generic approach, where a single endpoint can translate to a number of commands. I often see the command name as pat of the URL. A prefix and suffix are used to translate the path segment to a fully qualified classname. For example: com.mycompany.myapp.api.<>Command. The payload of the request is used to create the command instance.

Cheers,

Allard

Hi Allard,
can you elaborate more on second approach (if possible show example)?

what do you mean by prefix and suffix in this case? How do the endpoint url look like? It looks like it’s enough to have one generic method (with Object as input param) which will be responsible for handling all actions (or for many actions).

Thanks

Lukas

Lukas,

Although the 2nd option sound interesting, do realise you are coupling your client(s) to more than just a REST API. You are effectively asking them to include the correct command (as URL or Header) in their service request. Which implies you expect them to understand your domain’s Commands. Basically your domain is leaking into your REST interface.

Cheers,
Benoît

Hi Benoît,
so better approach is to have something like

PUT
rest/user/{id}/changePassword and include ChangePasswordCommand in body
PUT
rest/user/{id}/changeDetails and include ChangeDetailsCommand in body

PUT
rest/user/{id}/disable

PUT
rest/user/{id}/enable

Lukas,

That’s more like it, yes. Though in terms of RESTful API I would avoid the use of term as ‘change’, ‘update’, ‘remove’ in the URLs.
The HTTP verb (GET, PUT,POST,DELETE,(PATCH) ) will tell what sort of operation to perform on the resource. If the operation is other that CRUD, HTTP POST is your best option. e.g. POST /user/{id}/disable.
There is a lot of material on how to design RESTful apis on the web.

Cheers,
Benoît