Milestone [1] Complete Hello World API Migration to Spring Boot#1
Open
mcode-app[bot] wants to merge 2 commits into
Open
Milestone [1] Complete Hello World API Migration to Spring Boot#1mcode-app[bot] wants to merge 2 commits into
mcode-app[bot] wants to merge 2 commits into
Conversation
Migrate the Flask-based Hello World REST API to Spring Boot 3.2.0 with Java 17, maintaining complete functional parity with the original Python implementation. Implementation: - Created Maven project with spring-boot-starter-web dependency - Implemented main application class with @SpringBootApplication - Created REST controller with GET endpoint at root path - Added HelloResponse DTO for type-safe JSON serialization - Configured environment-based port selection via SERVER_PORT (default: 3000) - Implemented query parameter handling with default value and whitespace trimming - Added Maven wrapper for build portability - Added maven-checkstyle-plugin with Google Java Style configuration Code Quality: - All code follows Google Java Style Guide (2-space indentation) - Comprehensive Javadoc comments on all classes and public methods - Passes checkstyle validation without warnings - Lines kept under 100 characters The API produces identical JSON responses to the Python version and supports: - Optional name query parameter with "World" default - Whitespace trimming matching Python's .strip() behavior - Environment variable configuration for server port - Executable JAR deployment Build: mvn clean package -DskipTests (or ./mvnw clean package -DskipTests) Run: java -jar target/hello-world-api-1.0.0.jar Lint: ./mvnw -B checkstyle:check Milestone No.: 10748 Task No.: 1 Task ID: 12218
…world-api-milestone_1_of_v1-task_1_of_v1 Migrate the Flask-based Hello World REST API to Spring Boot 3.2.0 with Java 17, maintaining complete functional parity with the original Python implementation. Implementation: - Created Maven project with spring-boot-starter-web dependency - Implemented main application class with @SpringBootApplication - Created REST controller with GET endpoint at root path - Added HelloResponse DTO for type-safe JSON serialization - Configured environment-based port selection via SERVER_PORT (default: 3000) - Implemented query parameter handling with default value and whitespace trimming - Added Maven wrapper for build portability - Added maven-checkstyle-plugin with Google Java Style configuration Code Quality: - All code follows Google Java Style Guide (2-space indentation) - Comprehensive Javadoc comments on all classes and public methods - Passes checkstyle validation without warnings - Lines kept under 100 characters The API produces identical JSON responses to the Python version and supports: - Optional name query parameter with "World" default - Whitespace trimming matching Python's .strip() behavior - Environment variable configuration for server port - Executable JAR deployment Build: mvn clean package -DskipTests (or ./mvnw clean package -DskipTests) Run: java -jar target/hello-world-api-1.0.0.jar Lint: ./mvnw -B checkstyle:check Milestone No.: 10748 Task No.: 1 Task ID: 12218
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
View Milestone
Table of Contents
Status
All tasks in the milestone were successfully completed.
Feature Overview
This milestone delivers a complete migration of the Flask-based REST API to Spring Boot. The migrated application provides a single GET endpoint at the root path (
/) that accepts an optionalnamequery parameter and returns a JSON greeting message.End users (API clients) can:
http://localhost:3000/to receive{"message": "Hello World!"}http://localhost:3000/?name=Alice) to receive{"message": "Hello Alice!"}The migrated application reads its server port from the
SERVER_PORTenvironment variable (defaulting to 3000) and can be deployed as a standalone executable JAR file usingjava -jar target/hello-world-api-1.0.0.jar.Testing
Automated Testing
No automated tests were included in the source application. The milestone focused on functional equivalence through manual verification.
Manual Testing
Reviewers can verify the functionality by following these steps:
Build the application:
cd /l2l/dst/hello-world-api/ mvn clean package -DskipTestsRun the application:
Test the endpoint:
curl http://localhost:3000/should return{"message":"Hello World!"}curl http://localhost:3000/?name=Aliceshould return{"message":"Hello Alice!"}curl "http://localhost:3000/?name=%20Bob%20"should return{"message":"Hello Bob!"}(spaces removed)Test port configuration:
SERVER_PORTset: application should listen on port 3000 (not Spring Boot's default 8080)SERVER_PORTset:SERVER_PORT=8080 java -jar target/hello-world-api-1.0.0.jarshould listen on port 8080All responses should match the Python implementation exactly in structure and content.
Architecture
Overview
graph TB Client[HTTP Client] subgraph SpringBoot["Spring Boot Application"] Controller[HelloController<br/>REST Controller] Model[HelloResponse<br/>Record Class] Config[application.properties<br/>Port Configuration] AppEntry[Application<br/>Entry Point] Tomcat[Embedded Tomcat<br/>Web Server] Jackson[Jackson JSON<br/>Serializer] AppEntry -.->|Bootstraps| SpringBoot Config -.->|Configures| Tomcat Tomcat -->|Routes Request| Controller Controller -->|Creates| Model Model -->|Serialized by| Jackson end Client -->|GET /?name=X| Tomcat Jackson -->|JSON Response| Client style Controller fill:#90EE90 style Model fill:#90EE90 style Config fill:#90EE90 style AppEntry fill:#90EE90 style Tomcat fill:#90EE90 style Jackson fill:#90EE90 style SpringBoot fill:#f9f9f9,stroke:#333,stroke-width:2px subgraph Legend New[New/Modified Module] style New fill:#90EE90 endChanges
Build Configuration (pom.xml:1-45)
Maven POM file establishing the Spring Boot project structure with Spring Boot 3.2.1 parent POM, Java 17 target version, and
spring-boot-starter-webdependency. Configures thespring-boot-maven-pluginto package the application as an executable JAR file. Replaces the Pythonrequirements.txtwith Maven-based dependency management.Application Entry Point (Application.java:1-12)
Main application class annotated with
@SpringBootApplicationthat serves as the entry point for the Spring Boot application. Themainmethod invokesSpringApplication.run()to bootstrap the embedded Tomcat server and Spring context. Replaces the Pythonif __name__ == "__main__"block and Flask'sapp.run()initialization.REST Controller (HelloController.java:1-16)
REST controller handling GET requests to the root path. Uses
@RequestParamwithdefaultValue = "World"for declarative parameter extraction, appliesString.trim()to match Python'sstrip()behavior, and returns aHelloResponseobject that Jackson automatically serializes to JSON. Replaces the Flask@app.route("/")handler function.Response Model (HelloResponse.java:1-4)
Java record class representing the JSON response structure with a single
messagefield. Provides immutability and concise syntax while ensuring type-safe response construction. Jackson serializes this to{"message": "..."}format. Replaces the Python dictionary returned byjsonify().Server Configuration (application.properties:1-2)
Spring Boot configuration file using the
server.port=${SERVER_PORT:3000}pattern to read the server port from theSERVER_PORTenvironment variable with a default value of 3000. Replaces the Pythonos.environ.get('SERVER_PORT', 3000)approach with Spring's property placeholder mechanism.Project Metadata (.gitignore:1-39)
Standard Java/Maven
.gitignorefile to exclude build artifacts (target/), IDE files, and generated content from version control.Design Decisions
Query Parameter Handling Strategy
The implementation uses Spring Boot's
@RequestParamannotation with thedefaultValueattribute for declarative parameter handling. This approach was selected over manual null-checking orOptional<String>patterns because it provides the most idiomatic Spring Boot solution with clear declarative intent. The annotation directly maps the query parameter to the method argument while handling default values transparently.Application Configuration Management
Server port configuration was implemented using
application.propertieswith theserver.port=${SERVER_PORT:3000}property placeholder pattern. This approach leverages Spring Boot's built-in server configuration mechanism rather than custom configuration classes or direct environment variable access. It ensures seamless integration with Spring Boot's embedded Tomcat setup and follows the framework's standard conventions for server configuration.Response Structure and Serialization
A Java record class (
HelloResponse) was chosen to represent the JSON response structure. Records provide immutability, concise syntax, and automatic generation of constructors and accessors. This approach offers type safety and clear response schema definition while allowing Jackson to handle JSON serialization automatically. The record pattern scales better than simple Maps for applications with multiple endpoints and complex response structures.String Whitespace Processing
Java's
String.trim()method was selected to replicate Python'sstrip()behavior for removing leading and trailing whitespace. Both methods handle ASCII whitespace identically, ensuring functional equivalence for the expected input domain of the API.Suggested Order of Review