A basic API for an animal shelter that can be used to list available cats and dogs at the shelter available for adoption.
- Technologies Used
- Setup/Installation Requirements
- Api Info/Endpoinst
- Known Bugs
- License
- Contact Information
- C#
- ASP.Net Core
- ASP.NET MVC
- Entity Framework
- MySql Database
- Dotnet-ef
- Swagger
- If you don't already have C# and .NET installed on your computer, you can get the Software Develment Kit or SDK for Mac here: Dot.Net for Mac and for Windows here: Dot.Net for Windows. Follow the instructions detailed in both links above for set up.
- If not already installed, download: MySql Community
- If not already installed, download: MySql Workbench
- Follow the instruction here for configuring MySql.
- Open the terminal on your local machine and navigate to where you want to clone the project
- Run the following command: git clone https://github.com/ShanGGraff/AnimalShelter.Solution.
- Navigate to the
AnimalShelter/
directory and create a file named:appsettings.json
. In this file, add the folling configuration to be able to create the table used by the application:
{
"Logging": {
"LogLevel": {
"Default": "Warning",
"System": "Information",
"Microsoft": "Information"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Port=3306;database=animal_shelter;uid=root;pwd=[YOUR-PASSWORD-HERE];"
}
}
- If you don't already of migragtions installed for creating the table, add the package with the following:
dotnet add package Microsoft.EntityFrameworkCore.Design -v 5.0.0
on the command line in the AnimalShelter main directory. - In the SweetAndSavory main directory run
dotnet build
on the command line to check for errors - Next run
dotnet ef migrations add Initial
. Note when making changes to the schema (i.e. making changes in the models that affect the database such as adding a new attribute, you would change "Initial" to something more descriptive of what change you are making to the table. - Nex run
dotnet ef database update
to update the table/s. I've included values in the AnimalShelterContext.cs to seed the database with some animal entries for testing. - Run
dotnet build
again to make sure there are no errors. - If everything builds correctly, run
dotnet run
on the command line to start the AnimalShelter API.
- Once the API is running, you can test the API endpoints on the index page: https://localhost:5001/index.html using Swagger.
The API enpoints are the following:
GET /api/Animals (returns a list of the animals at the shelter)
POST /api/Animals (allows user to add new animal to the database)
GET /api/Animals/{id} (list an animal by a specific id)
PUT /api/Animals/{id} (change information about a specific animal)
DELETE /api/Animals/{id} (delete a specific animal by id)
Here is an example of available user queries:
- A basic list of all the animals at the shelter:
https://localhost:5001/api/Animals/
- Listing an animal by id:
http://localhost:5000/api/Animals/2
- Searching by multiple attributes
http://localhost:5000/api/animals/?species=cat&gender=female&age=1
- No known
Copyright (c) 2021 Creators
- Shane Graff copellius@gmail.com
- Github page: ShanGGraff
- LinkedIn: Shane Graff