Skip to content

This application will explore how to create REST APIs for CRUD operations using Spring Boot framework.

License

Notifications You must be signed in to change notification settings

rheien/Spring-Boot-REST-API-Example-Volleyballteam

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring-Boot-REST-API-Example-Volleyballteam

This application will explore how to create REST APIs for CRUD operations using Spring Boot framework.

To start the application, run the following command in your terminal:

mvn spring-boot:run

How to use the application

With the application running, open your browser and navigate to http://localhost:8080/swagger-ui/index.html. You will see the Swagger UI page from where you can test the REST APIs.

Of course, you can also use Postman or any other REST client to test the APIs. The REST API can be accessed at http://localhost:8080/api/teams.

Following endpoints are available in the application:

GET http://localhost:8080/api/teams

As a curl command:

curl --location 'http://localhost:8080/api/teams'

Get all teams in response as JSON:

[
    {
        "name": "Füchse",
        "trainer": "Hermann",
        "location": "Berlin",
        "players": [
            {
                "id": "1",
                "name": "Hans",
                "position": "Libero"
            }
        ]
    },
    {
        "name": "Dolphin",
        "trainer": "Joos",
        "location": "Stuttgart",
        "players": []
    }
]
GET http://localhost:8080/api/teams/{name}

As a curl command:

curl --location 'http://localhost:8080/api/teams/Füchse'

Get a team by name in response as JSON:

{
    "name": "Füchse",
    "trainer": "Hermann",
    "location": "Berlin",
    "players": [
        {
            "id": "1",
            "name": "Hans",
            "position": "Libero"
        }
    ]
}
GET http://localhost:8080/api/teams/players

As a curl command:

curl --location 'http://localhost:8080/api/teams/players'

Get all players in response as JSON:

[
    {
        "id": "1",
        "name": "Hans",
        "position": "Libero"
    }
]
GET http://localhost:8080/api/teams/players/{id}

As a curl command:

curl --location 'http://localhost:8080/api/teams/players/1'

Get a player by id in response as JSON:

{
    "id": "1",
    "name": "Hans",
    "position": "Libero"
}
GET http://localhost:8080/api/teams/{name}/players

As a curl command:

curl --location 'http://localhost:8080/api/teams/Füchse/players'

Get all players by team name in response as JSON:

[
    {
        "id": "1",
        "name": "Hans",
        "position": "Libero"
    }
]
POST http://localhost:8080/api/teams/team-management

As a curl command:

curl --location --request POST 'http://localhost:8080/api/teams/team-management' \
--header 'Content-Type: application/json' \
--data '{
    "name": "Feuer",
    "trainer": "Müller",
    "location": "Hannover"
}'

Create or update a team in response as JSON:

{
    "name": "Feuer",
    "trainer": "Müller",
    "location": "Hannover",
    "players": []
}
POST http://localhost:8080/api/teams/team-management/players

As a curl command:

curl --location --request POST 'http://localhost:8080/api/teams/team-management/players' \
--header 'Content-Type: application/json' \
--data '{
    "name": "Jochen",
    "position": "Opposite Hitter",
    "team": {
        "name": "Füchse"
    }
}'

Add a player to a team in response as JSON:

{
    "name": "Füchse",
    "trainer": "Hermann",
    "location": "Berlin",
    "players": [
        {
            "id": "1",
            "name": "Hans",
            "position": "Libero"
        },
        {
            "id": "2",
            "name": "Jochen",
            "position": "Opposite Hitter"
        }
    ]
}
DELETE http://localhost:8080/api/teams/team-management/players

As a curl command:

curl --location --request DELETE 'http://localhost:8080/api/teams/team-management/players' \
--header 'Content-Type: application/json' \
--data '{
    "name": "Jochen",
    "position": "Opposite Hitter",
    "team": {
        "name": "Füchse"
    }
}'

Remove a player from a team in response as JSON:

{
    "name": "Füchse",
    "trainer": "Hermann",
    "location": "Berlin",
    "players": [
        {
            "id": "1",
            "name": "Hans",
            "position": "Libero"
        }
    ]
}

About

This application will explore how to create REST APIs for CRUD operations using Spring Boot framework.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages