Skip to content

cmalangone/spring-boot-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

This example builds a simple REST API. (retrieve, update, delete and insert a person)

Keywords

Maven
Java 1.8
Spring Boot
Spring Data REST
Asciidoctor
H2 (in memory db)

Building this Project

This project is built with Maven (http://maven.apache.org) so make sure you have an up-to-date installation of Maven before proceeding.

Clone this project, change to the root spring-boot-example directory and run

mvn clean install

to build the binary of this project.

Execute the application

java -jar  target/sdo-rest-api-0.0.1-SNAPSHOT.jar

or

mvn spring-boot:run

Welcome page

The root shows a welcome page

http://localhost:8080

REST API example

Retrieve the list of people

curl --request GET http://localhost:8080/api/people

Query by person id

curl --request GET http://localhost:8080/api/person/101

Add a list of people

curl --header "Content-Type: application/json" --request POST -d '{  
   "person":[     {
      "first_name": "Cinzia",
      "last_name": "Bianchi",
      "age": "19",
      "favourite_colour": "yellow"
    },
    {
      "first_name": "Sarah",
      "last_name": "Robinson",
      "age": "54",
      "favourite_colour": "blue"
    } ]
}' http://localhost:8080/api/addpeople

Update the info for a list of people

curl --header "Content-Type: application/json" --request PUT \
-d '{  
   "person":[     {
      "id":1 ,
      "first_name": "Cinzia",
      "last_name": "Doe",
      "age": "27",
      "favourite_colour": "purple"
    }]
}' http://localhost:8080/api/updatepeople

Delete a list of people by ids

curl --header "Content-Type: application/json" --request DELETE \
-d '{  
   "person":[     {
      "id":1 
    }]
}' http://localhost:8080/api/deletepeople

REST API 404 example

If the person is not present, the status code is 404.

curl -I --request GET http://localhost:8080/api/person/1

HTTP/1.1 404
Content-Length: 0
Date: 

ASCIIDOCTOR

Next step is integrate ASCIIDOCTOR into the code in order to create the REST API docs.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages