Using Domain Driven Design (in short DDD) it is common to follow the principles of hexagonal, onion or ports and adapters architecture. This means that your domain logic should be independent from how it is connected to the outside world. For instance you shouldn’t see any messaging or REST specific logic in domain logic. Even though this sounds easy, in past projects I came across loads of messy code when connecting the outside world (like a REST Endpoint) with the domain. Doing it in a more functional way using functions solves a lot of problems and leads to cleaner code. I want to share this in this blog post.