Vivek-Prajapatii / teamplayer

A REST API for Team and Player using SpringBoot and MySQL database

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A REST API tool for Team and Player built using Java SpringBoot and used the MySQL database to store the data with the help of Object Relational Mapping(ORM)-Hibernate

Here we have two entities Team and Player and have one-to-many relationship.

Get Started

Usage

This is an example of running a service locally(localhost) using port 9090.

localhost:9090/<endpoints>

Here is a list of all the endpoints that you get on both the entities, the Team and the Player

  • Create
  • Find by id
  • Update
  • Delete
  • List

Endpoints for Team

Create team (POST)

Here, to create a team you need to place the Json object of team in the Request Editor of Postman and hit the below URL. And you will be using the POST method to store the team info.

localhost:9090/team

Create Team

FindById Team (GET)

With the help this endpoint you can get the specific team from the multiple teams in the Json objects. Here you will be using the GET to fetch the data.

So lets fetch the data of team 2.

localhost:9090/team/{teamId}

getTeamById

Update Team (PUT)

To update the team you need to specify the teamId as a pathVariable using the PUT method.

So lets update the team 1's location to Bombay from Mumbai

localhost:9090/team/{teamId}

updateTeam

Delete Team (DELETE)

Let us now Delete the team 2 using the Delete method.

localhost:9090/team/{teamId}

updateTeam

List Teams (GET)

This will get you the list of all the teams present in the database.

localhost:9090/teams
[
    {
        "name": "MI",
        "location": "Bombay",
        "id": 1,
        "players": [
            {
                "name": "Hardik",
                "age": 28,
                "createdAt": "2022-02-20T17:54:30.095+00:00",
                "id": 1,
                "upadatedAt": "2022-02-20T17:54:30.095+00:00"
            },
            {
                "name": "Rohit",
                "age": 29,
                "createdAt": "2022-02-20T17:08:22.994+00:00",
                "id": 2,
                "upadatedAt": "2022-02-20T17:08:22.994+00:00"
            }
        ],
        "created": null,
        "updated": "2022-02-20T17:48:56.587+00:00"
    },
    {
        "name": "KKR",
        "location": "Kolkata",
        "id": 2,
        "players": [
            {
                "name": "Shubhman",
                "age": 25,
                "createdAt": "2022-02-20T17:19:40.270+00:00",
                "id": 4,
                "upadatedAt": "2022-02-20T17:19:40.270+00:00"
            }
        ],
        "created": "2022-02-20T17:11:21.097+00:00",
        "updated": "2022-02-20T17:11:21.097+00:00"
    }
]

Endpoints for Players

Create Player (POST)

To add a player first you need teamId i.e. in which team you want to add the player.

localhost:9090/team/{teamId}/player

Create player

FindById Player (GET)

You can get the data of any player by the below URL.

localhost:9090/player/{playerId}

getPlayerById

Update Player (PUT)

From this endpoint you can update the data of the player by just giving the playerId as the pathVariable, by using the PUT method

localhost:9090/player/{playerId}

Let's update the player 1's name from Hardik to Krunal and age from 28 to 29.

update player

The following is the result of the above operation.

update player

Delete Player (DELETE)

localhost:9090/player/{playerId}

Deleteting the data of player 1 results in below output.

Delete player

List Player (GET)

Getting all the players from the Player Entity.

localhost:9090/players

List Players

About

A REST API for Team and Player using SpringBoot and MySQL database


Languages

Language:Java 100.0%