Loading repository data…
Loading repository data…
cip-p / repository
Spring boot example for creating a CRUD Rest API using in memory H2 database.
/GET /POST /PUT /DELETE APIs for managing cakes.
8081src/test/resources/mappings/cakes.json file)WebTestClient.github folder and Actions tab on this pageIn order to build the project, you will have to install the following:
Enable annotation processing (for IntelliJ IDEA).mvn clean install
docker build -t cake-service .
mvn spring-boot:run
docker run -p 8081:8081 cake-service
Swagger endpoint: http://localhost:8081/swagger-ui/index.html
OpenApi endpoint: http://localhost:8081/v3/api-docs
Important: swagger/openapi dependency for spring-boot 3 is now springdoc-openapi-starter-webmvc-ui
All APIs are secured using basic auth. Use the following credentials when making requests:
username=cake-user
password=cake-password-which-should-be-kept-in-a-secret-place-and-injected-when-application-is-deployed
curl 'localhost:8081/cakes' \
-u "cake-user:cake-password-which-should-be-kept-in-a-secret-place-and-injected-when-application-is-deployed"
curl 'localhost:8081/cakes/15' \
-u "cake-user:cake-password-which-should-be-kept-in-a-secret-place-and-injected-when-application-is-deployed"
curl -X POST 'localhost:8081/cakes' \
-u "cake-user:cake-password-which-should-be-kept-in-a-secret-place-and-injected-when-application-is-deployed" \
--header 'Content-Type: application/json' \
--data-raw '{
"title": "some title",
"description": "some description"
}'
curl -X PUT 'localhost:8081/cakes/15' \
-u "cake-user:cake-password-which-should-be-kept-in-a-secret-place-and-injected-when-application-is-deployed" \
--header 'Content-Type: application/json' \
--data-raw '{
"title": "some title updated",
"description": "some description updated"
}'
curl -X DELETE 'localhost:8081/cakes/15' \
-u "cake-user:cake-password-which-should-be-kept-in-a-secret-place-and-injected-when-application-is-deployed"
CakeDatabasePopulatorTest integration test is using Wiremock to stub the external URL for loading cakes. The file mapping of that response is located under src/test/resources/mappings/cakes.json.