Skip to content

supermanue/crudexample-http4s-zio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ZIO EXPERIMENT

This is an experiment with ZIO + HTTP4s + DOOBIE. It is fully described in a series of posts in MEDIUM. It can be regarded as the continuation of THIS BLOG POST which serves as the inspiration of this project.

The basic idea is to have a server running with that software stack. I want to make it as production-like as possible, so I have refactored the original code adding some extra layers and testing.

Intro

What this project does is start a small server with 2 endpoints: one allows to write a User, and the other to retrieve it. There are example CURLS defining the functionality:

curl --location --request POST 'localhost:8083/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "id": "1",
    "name": "manuel"
}'
curl --location --request GET 'localhost:8083/1'
curl --location --request DELETE 'localhost:8083/1'

Architecture and code designn

My proposed architecture is:

  • Main: file that connects the wires and runs the server
  • HTTP: package with the HTTP server
  • DOMAIN: package with the Domain logic
    • Model:
    • Service: business logic regarding the domain objects
    • Ports: interfaces defining the desired I/O
  • ADAPTER: package with implementation for the ports
  • CONFIGURATION: boring configuration stuff

Storage

The project uses a H2 in-memory DB to store Users.

Testing

Testing is performed in different layers:

  • Domain: unit tests for the services residing in the Service package.
    • I am using a mock DB in here -just an array- to isolate responsibilities
    • I am using property-based testing for the model whenever possible
    • For a full description of the test see Road to ZIO[N]: chapter 3, testing the Domain
  • Adapters: unit tests for the adapters, making sure that they implement correctly the desired functionalities.
    • Also described in section 4
  • Full testing of the HTTP layer with integration tests. This way we verify that:

TODO

This is an ongoing process and it is still not finished. Some missing sections are:

  • Clean (probably with a full refactor) the HTTP layer.

  • Scalability tests

    • attack the API with something like Gatling and see how ZIO+HTTP4S+DOOBIE behaves under heavy loads
  • Kafka Producer/Consumer

    • I want to test how to write and read Kafka stuff with ZIO
  • Update to ZIO2

    • while this tutorial has been written, a new version of ZIO has been released. It is supposed to simplify most of the pain points, so it is definitely worth to take a deep look at it.

About

ZIO experiment

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages