The REST API performs CRUD operations on Animal objects as described below.
- Get the project
-
clone
git clone https://github.com/your-repo/animal-crud-api.git -
download zip.
-
- Open the project in IntelliJ or your preferred IDE.
- The
/src/main/resources/application.propertiesfile is the configuration for the MySQL database on your localhost.- The database name is set in the
datasource.urlproperty between the last/and the?. In this case, the database name isanimal. - You MUST have the MySQL database running before running the project!
- Open your XAMPP Control Panel.
- Start the Apache server.
- Start MySQL.
- Click on MySQL "Admin" to open up phpMyAdmin.
- Ensure the
animaldatabase is created and theanimaltable exists (you can use the SQL script provided earlier).
- The database name is set in the
- Build and run the main class. You should see new data being stored in the
animaldatabase as you interact with the API.
Use POSTMAN to try the following endpoints:
GET /animal/all
http://localhost:8080/animal/all
[
{"animalId": 1, "name": "Blue Jay", "species": "Bird", "habitat": "Forests", "description": "A vibrant blue bird found in North America."},
{"animalId": 2, "name": "Great Blue Heron", "species": "Bird", "habitat": "Wetlands", "description": "A large wading bird found in North American wetlands."}
]GET /animal/{animalId}
http://localhost:8080/animal/1
{
"animalId": 1, "name": "Blue Jay", "species": "Bird", "habitat": "Forests", "description": "A vibrant blue bird found in North America."
}POST /animal/add
http://localhost:8080/animal/add
{
"name": "Russian Blue Cat",
"species": "Mammal",
"habitat": "Domestic",
"description": "A domestic cat breed known for its short blue-grey coat."
}GET /animal/species/{species}
http://localhost:8080/animal/species/Bird
[
{"animalId": 1, "name": "Blue Jay", "species": "Bird", "habitat": "Forests", "description": "A vibrant blue bird found in North America."},
{"animalId": 2, "name": "Great Blue Heron", "species": "Bird", "habitat": "Wetlands", "description": "A large wading bird found in North American wetlands."}
]GET /animal/search?name=blue
http://localhost:8080/animal/search?name=blue
[
{"animalId": 1, "name": "Blue Jay", "species": "Bird", "habitat": "Forests", "description": "A vibrant blue bird found in North America."},
{"animalId": 3, "name": "Russian Blue Cat", "species": "Mammal", "habitat": "Domestic", "description": "A domestic cat breed known for its short blue-grey coat."}
]PUT /animal/update/{animalId}
http://localhost:8080/animal/update/1
{
"name": "Updated Blue Jay",
"species": "Bird",
"habitat": "Updated Forests",
"description": "Updated description."
}DELETE /animal/delete/{animalId}
http://localhost:8080/animal/delete/1