') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); GitHub - DavFilsDev/springboot-student-api: REST API exercise demonstrating data handling with request params, path variables, request body, and headers in Spring Boot. · GitHub
Skip to content

Latest commit

History

26 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Spring Boot Student API

Overview

A REST API exercise demonstrating data handling in Spring Boot, covering request parameters, path variables, request bodies, and HTTP headers with in-memory data storage.

Learning Objectives

  • Handle HTTP requests using Spring Boot annotations
  • Process different types of input data (query params, request body, headers)
  • Implement RESTful endpoints (GET, POST)
  • Manage application state in memory
  • Perform content negotiation based on Accept headers

Endpoints

GET /welcome

Returns a personalized welcome message.

Request Parameter:

  • name (string, optional) - Name to greet

Response:

  • 200 OK - "Welcome "

Example:

GET /welcome?name=John
Response: Welcome John

POST /students

Adds a list of students to the in-memory storage.

Request Body: Array of student objects

[
{
"reference": "STU001",
"firstName": "John",
"lastName": "Doe",
"age": 20
},
{
"reference": "STU002", "firstName": "Jane",
"lastName": "Smith",
"age": 22
}
]

Response: Comma-separated list of all stored students

John Doe, Jane Smith

GET /students

Retrieves all stored student names.

Accept Header:

  • text/plain (default) - Returns student names in plain text format
  • Other values - Returns error message "Format non supporté"

Response:

  • 200 OK - "John Doe, Jane Smith"
  • 400 Bad Request - "Format non supporté" (if Accept header is not text/plain)

Technologies

  • Java 17+
  • Spring Boot 3.x
  • Spring Web

Project Structure

src/main/java/com/example/demo/
├── controller/
│ └── StudentController.java
├── service/
│ └── StudentService.java
├── model/
│ └── Student.java
└── repository/
└── StudentRepository.java

Setup Instructions

  1. Clone the repository
git clone https://github.com/DavFilsDev/springboot-student-api
  1. Navigate to the project directory
cd springboot-student-api
  1. Build the project
./mvnw clean install
  1. Run the application
./mvnw spring-boot:run
  1. Test the endpoints
# Test GET /welcome
curl "http://localhost:8080/welcome?name=John"# Test POST /students
curl -X POST http://localhost:8080/students \
-H "Content-Type: application/json" \
-d '[{"reference":"STU001","firstName":"John","lastName":"Doe","age":20}]'# Test GET /students with Accept header
curl -H "Accept: text/plain" http://localhost:8080/students

Key Spring Boot Concepts

  • @RestController - Defines RESTful controller
  • @GetMapping / @PostMapping - HTTP method mappings
  • @RequestParam - Extract query parameters
  • @RequestBody - Extract and deserialize request body
  • @RequestHeader - Extract HTTP headers
  • In-memory storage using collections (List, Map)

Exercise Progression

  1. Part A - Basic GET endpoint with query parameters
  2. Part B - POST endpoint with request body processing
  3. Part C - GET endpoint with header-based content negotiation

License

Educational purposes only

About

REST API exercise demonstrating data handling with request params, path variables, request body, and headers in Spring Boot.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages