The research project goal to understand what is a web framework tech stack.
The project includes three important parts:
- HTTP Protocol: The client can send a request, and then the server listens on a socket port. When the server receives the data, it processes it from request to response.
- Core Web Framework: This core framework provides developers with tools to build their services quickly.
- Domain Service: Developers build domain-specific services using the web framework. This is an easily user login system.
- The client can send an HTTP request.
- The HTTP request deserializes HTTP information, including the method, path, query, body, and headers, and then the server handles these requests.
- When the requested task is finished, the server serializes the data into an HTTP response.
- Finally, the client receives data from the HTTP response.
The current core stack includes the following components:
- Router:
- Developer can define controller, including request and response information.
- The router will automatically reflect the defined request and response to the target class.
- Finally, you can easily process received requests and transfer responses using your injection service.
- TransformBodyTypeHandler:
- When received a request needs to be deserialized and the transferred response needs to be serialized.
- TransformBodyTypeHandler will transform your defined data type to offer developers convenient usage.
- ExceptionHandler:
- If the service encounters any exceptions, you want to respond with a response-specific status code, message, and so on.
- ExceptionHandler can reduce the time needed to wrap the response format and efficiently decouple your code.
- You just need to define handling exceptions and register a custom ExceptionHandler, ExceptionHandler will automatically handle exceptions.
- Container:
- Container helps the system maintain the injection state in your controller and service, preventing your service from recreating the injection object with every request.
- You can freely choose injected objects and how to maintain the object state.
The service follows clean architecture and domain-driven design concepts in building its architecture
- Domain layer:
- This layer contains core domain knowledge of service, allowing you to wrap rich product domains and iteratively your best product.
- To maintain clarity, this layer should not depend on any other layers.
- Infrastructure layer:
- This layer's main responsibility is handling external data or services.
- You can define controllers to receive requests and transfer responses, access your database, manage third-party API, and so on.
- Application layer:
- This layer facilitates communication between the domain layer and the infrastructure layer for each use case.
- Locate the package named
UserSystem
. - Run
Main.java
- You will see the following information indicating that the service has successfully started on port 8080:
Server started. Listening for connections on port 8080...
- At this point, you can try to send an HTTP request using Postman or any browser or in any other way.
- Mehod: POST
- Path: /api/users
- content-type: application/json
name | type |
---|---|
string | |
name | string |
password | string |
- status code: 201
- Mehod: POST
- Path: /api/users/login
- content-type: application/json
name | type |
---|---|
string | |
password | string |
- status code: 200
- content-type: application/json
- content-encoding: UTF-8
name | type |
---|---|
id | int |
string | |
name | string |
token | string |
- Mehod: PATCH
- Path: /api/users/1
- content-type: application/json
- Authorization: Bearer
name | type |
---|---|
newName | string |
- status code: 204
- Mehod: GET
- Path: /api/users
- Authorization: Bearer
name | type |
---|---|
keyword | string |
- status code: 200
- content-type: application/json
- content-encoding: UTF-8
name | type |
---|---|
id | int |
string | |
name | string |
If you are curious about the project, I have OOA and OOD design diagrams. Feel free to contact me to discuss anything you find interesting.