The objective is to learn how to use Functional Programming (FP) techniques such as Pure Functions, Immutability etc. However, in real world software systems side effects are desired business outcomes. This is an exercise to learn how to handle side-effects while using FP.
The usecase is a simple user registration process.
- User sends a Registration request with name, email, phoneNumber
- Validate the input:
name
andemail
should not be blank/empty - We need to verify whether a user already registered with same email? If yes, then respond with Conflict Request status with appropriate error message.
- Persist the user details in DB
- Publish a UserCreatedEvent to a MessageBroker like Kafka/RabbitMQ
This is a very common requirement in typical enterprise business applications where the business process results in side-effects.
The goal is to learn how to approach this usecase using FP.
- SpringBoot OO with side-effects
cd user-management
./mvnw test
./mvnw spring-boot:run
curl --location --request POST 'http://localhost:8080/api/users' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "Siva",
"email": "[email protected]",
"phone": "91919191"
}'