Week 4 - Rest APIs

Java Annotations

Introduction to REST

Spring Boot Setup

Writing Endpoints

Message Formats

Input Validation

Practice

Assignment

Back end Track

Week 4 Assignment

Analytics API

Overview

In this assignment, you will design and build a small REST API for analytics data using Spring Boot.

Many applications record limited, non-identifying usage data: which actions happen, when they happen, which part of the app produced them, and how often they occur. Product teams can use this data to answer questions such as: "How many actions were recorded today?", "Which type of action happened most often?", or "How many visitors or sessions were active?”

Your API will let a client submit analytics data, query stored data, manage individual records, and read a simple summary. You will design the API contract and implement it.

The application does not need a database yet. Store the data in memory using Java collections. This keeps the assignment focused on REST design, Spring Boot controllers, DTOs, validation, error handling, and service-layer logic.

<aside> ⚠️

Analytics should be privacy-respecting. In the EU, the GDPR does not simply ban all identifiers, but any data that can identify a person counts as personal data and must be handled with a lawful basis, clear purpose, data minimization, and care. For this assignment, do not store names, email addresses, raw account IDs, IP addresses, or raw user IDs.

For counting unique visitors, assume the frontend sends an anonymized session ID instead of a real user ID.

</aside>

Project Setup

Create a new Spring Boot project with Spring Initializr: https://start.spring.io

Settings

Use a clear package structure. Your exact package names are up to you, but your project should make these parts easy to find:

Requirements

Design

Before you start coding, design your API with a markdown file named API_DESIGN.md in the project root.

Your design should document the resources, supported actions, request bodies, response bodies, status codes, validation rules, and error responses. Choose the exact URIs and JSON shapes yourself.

API behavior

Your API must allow a client to:

API Quality Control

<aside> 💡

Service layer is the application layer behind the controller. It is where the business logic typically lives.

Later in Integration Testing, you will learn how to test your controllers properly. For this assignment, keep your controllers as thin as possible and unit test your services instead.

</aside>

Scoring Criteria

Your assignment will be assessed on:

Criteria Description Weight
API design Uses REST principles High
Core behavior The API supports submitting, listing, filtering, fetching, replacing, deleting, and summarizing analytics records. High
Validation and error handling Invalid input is rejected with clear responses, and missing resources are handled consistently. Medium
Unit tests The main service-layer logic is covered by JUnit tests. Medium
Code quality The project structure is easy to navigate and the names are expressive. Medium
Separation of concerns Controllers, services, DTOs, models, and error handling each have a clear role. Low

Submission

Follow the Assignment submission guide to learn how to submit the assignment


The HackYourFuture curriculum is licensed under CC BY-NC-SA 4.0 *https://hackyourfuture.net/*

CC BY-NC-SA 4.0 Icons

Built with ❤️ by the HackYourFuture community · Thank you, contributors

Found a mistake or have a suggestion? Let us know in the feedback form.