What should be returned from the API for CQRS commands?

前端 未结 3 933
感动是毒
感动是毒 2021-02-05 12:09

As far as I understand, in a CQRS-oriented API exposed through a RESTful HTTP API the commands and queries are expressed through the HTTP verbs, the commands being asynchronous

3条回答
  •  有刺的猬
    2021-02-05 12:34

    We had a long conversation in DDD/CRQS mailing list a couple of months ago (link). One part of the discussion was "one way command" and this is what I think you are assuming. You can find out that Greg Young is opposed to this pattern. A command changes the state and therefore prone to failure, meaning it can fail and you should support this. REST API with POST/PUT requests provide perfect support for this but you should not just return 202 Accepted but really give some meaningful result back. Some people return 200 success and also some object that contains a URL to retrieve the newly created or updated object. If the command handler fails, it should return 500 and an error message.

    Having fire-and-forget commands is dangerous since it can give a consumer wrong ideas about the system state.

提交回复
热议问题