/lab_rest_api

Primary LanguageJavaScript

Architecture
=================
We'll be using Express.js for our API. I don't want to come up with a complex architecture so I'd like to stick to the **3 Layer Architecture**:

![](2023-03-21-10-12-58.png)

Inside the **Controller** we'll be handling all stuff that is related to HTTP. That means we're dealing with requests and responses for our endpoints. Above that layer is also a little **Router** from Express that passes requests to the corresponding controller.

The whole business logic will be in the **Service Layer** that exports certain services (methods) which are used by the controller.

The third layer is the **Data Access Layer** where we'll be working with our Database. We'll be exporting some methods for certain database operations like creating a WOD that can be used by our Service Layer.

In our example we're not using a real database such as MongoDB or PostgreSQL because I'd like to focus more on the best practices itself. Therefore we're using a local JSON file that mimics our Database. But this logic can be transferred to other databases of course.