gxshub / rest-services-with-spring

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

REST Services with Spring

This is a "getting started" with the Spring Boot framework, in which we build a simple REST service.

First go to the Spring Initializr to download a Spring project template. Choose Maven in Project, Choose Java in Language. Choose a version of Spring Boot, for example 3.3.2. Choose Jar in Packaging and Java 21 (don't use other java version). In Dependencies, add Web, JPA and H2.

Click "GENERATE", download and extract the zip file. Open the project folder in the IDE.

Based on the dependence of classes, implement them in this following order: Library -> LibraryRepository -> LibraryController.

After running the Spring application, interact with it by using REST requests. The following are examples of requests in CMD (note. commands in PowerShell are different).

curl -X POST -H "Content-Type:application/json" -d "{\"name\":\"My Library\"}" http://localhost:8080/libraries
curl -X POST -H "Content-Type:application/json" -d "{\"name\":\"My Second Library\"}" http://localhost:8080/libraries
curl -X GET -H "Content-Type:application/json" http://localhost:8080/libraries

About


Languages

Language:Java 100.0%