Content
<aside> ๐ง
This page is currently under construction. Please check back later.
</aside>
<aside> ๐ญ
Practice exercises are optional and do not need to be submitted
</aside>
In this exercise, you will design a small REST API before writing any code. The API manages personal notes.
A note has these fields:
idtitlecontenttagpinnedFor each action in the table below:
Content-TypeContent-TypeThe first row is pre-filled as an example.
| Action | Method and URI | Request body&Content-Type | Response body&Content-Type |
|---|---|---|---|
| Get all notes | GET /api/v1/notes |
None |
JSON array of all notes. application/json |
| Get all notes. Filtered by tag | |||
| Get only pinned notes | |||
| Get a note by ID | |||
| Create a new note | |||
| Replace an existing note | |||
| Delete a note |
In this exercise, you will build the API you designed in Exercise 1. You will practice Spring Boot controllers, composed mapping annotations,ย @PathVariable,ย @RequestParam,ย @RequestBody, andย ResponseEntity.
net.hackyourfutureValidation this time.src/main/java/net/hackyourfuture/NotesAPI๐ note/
โโโ ๐ NoteController.java
โโโ ๐ models/
โโโ ๐ Note.java
In this exercise youโll expand the controller in Exercise 2 to be working with DTOs and keep your Note model internal. This will make the API boundary clearer.
๐ note/
โโโ ๐ NoteController.java
โโโ ๐ย dto/
โ โโโ ๐ย request/
โ โ โโโ ๐ CreateNoteRequest.java
โ โ โโโ ๐ UpdateNoteRequest.java
โ โโโ ๐ย response/
โ โโโ ๐ NoteResponse.java
โโโ ๐ models/
โโโ ๐ Note.java
CreateNoteRequestUpdateNoteRequestNoteResponseNow make your Notes API reject invalid input. You will practice Jakarta Bean Validation,ย @Valid, and a global exception handler.
If you havenโt added the validation dependency, you can add the below to pom.xml and reload Maven:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
title with length between 3-80 characters.content with max length of 2000tag with max length 30The HackYourFuture curriculum is licensed underย CC BY-NC-SA 4.0 *https://hackyourfuture.net/*

Built with โค๏ธ by the HackYourFuture community ยท Thank you, contributors
Found a mistake or have a suggestion? Let us know in the feedback form.