Skip to lesson

Mini project: ShopLite API skeleton

Every later module of this section adds one feature to the same project, so the skeleton you build now (folders, names, build and README) is the base the whole ShopLite REST API grows on.

What you'll build

You start a new repository, shoplite-api. Your Section 14 ShopLite projects stay as they are: their API design (resources, URLs, status codes) and the Section 13 business rules come over feature by feature in the next modules, now on Spring Boot. Generate the project with Spring Initializr, keep the main class in com.shoplite, and add one package per feature: product, category, customer, order, plus common for shared code. This layout is called package by feature.

The only endpoint so far is GET /api. It answers with the app's name and version as JSON, read from application.properties, so anyone can check which app and which version is running on an address. The project builds into one runnable jar, has a .gitignore that keeps build output and secrets out of Git, and a README that tells a stranger how to run it.

Sample run (times, PIDs and paths will differ)
> .\mvnw clean package
...
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
...
[INFO] Building jar: C:\Users\asha\shoplite-api\target\shoplite-api-0.1.0.jar
...
[INFO] BUILD SUCCESS

> java -jar target/shoplite-api-0.1.0.jar
...  : Starting ShopliteApiApplication v0.1.0 using Java 19.0.2 with PID 12500 (...)
...  : Tomcat started on port 8080 (http) with context path '/'
...  : Started ShopliteApiApplication in 4.933 seconds (process running for 6.165)

(in a second terminal)
> curl -i http://localhost:8080/api
HTTP/1.1 200
Content-Type: application/json
Content-Length: 41
Date: Fri, 16 Oct 2026 05:17:55 GMT

{"name":"shoplite-api","version":"0.1.0"}

> curl http://localhost:8080/api/products
{"timestamp":"2026-10-16T05:17:55.729Z","status":404,"error":"Not Found","path":"/api/products"}

Requirements

  • 1The project is generated by Spring Initializr: Maven, Java 17, Spring Boot 4.1.x, Jar, group com.shoplite, artifact shoplite-api, dependency Spring Web.
  • 2The main class ShopliteApiApplication stays in the root package com.shoplite.
  • 3Packages product, category, customer, order and common exist under com.shoplite, each with a package-info.java saying what it is for.
  • 4application.properties sets spring.application.name=shoplite-api and shoplite.api.version, filled from the pom's version.
  • 5GET /api returns {"name":"shoplite-api","version":"0.1.0"} with status 200, from ApiInfoController in com.shoplite.common.
  • 6mvnw clean package passes the contextLoads test and builds target/shoplite-api-0.1.0.jar, which runs with java -jar.
  • 7.gitignore excludes target/, IDE folders, logs and secret files; README.md explains the structure and how to run and package the app.
  • 8The code is pushed to a public GitHub repository named shoplite-api.

Milestones

0/5 done · commit and push after each one
  1. Generate and run shoplite-api

    mvnw spring-boot:run ends with Started ShopliteApiApplication, and curl http://localhost:8080/ gives a 404 JSON body.

  2. Add the feature packages

    src/main/java/com/shoplite has product, category, customer, order and common, each with a package-info.java.

  3. Name and version in application.properties

    After mvnw package, the jar's application.properties contains shoplite.api.version=0.1.0.

  4. GET /api returns the name and version

    curl http://localhost:8080/api prints {"name":"shoplite-api","version":"0.1.0"}.

  5. Package, document and push

    java -jar target/shoplite-api-0.1.0.jar answers /api, and the code is on GitHub with a README.

Build it in your own GitHub repository and push after each milestone. When everything works, mark the project as complete.

Extra challenges (optional)

Do any you like, each on its own branch, so your main project keeps working.

  1. Add "java" to the response: the Java version the app runs on, from System.getProperty("java.version"), as a third record component.· easy

  2. Run the jar on port 9090 without changing any file, and update the README with that command.· easy

  3. Write a test ApiInfoControllerTests that starts the app with @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) and checks that /api returns version 0.1.0.· medium

Solution

Opens when you add your repository link.

Finish up

Mark complete & continue

Next: Beans and the application context