Simple REST API for managing dogs. Built with ASP.NET Core and Entity Framework.
- Check if API is working (ping endpoint)
- Get list of dogs with sorting and pagination
- Add new dogs with validation
- Limit too many requests (10 per second)
- Install .NET 8.0 SDK
- Open
appsettings.jsonand update connection string if needed - Run these commands:
dotnet ef migrations add InitialCreate
dotnet ef database update
dotnet runThe API will start at http://localhost:5000
curl http://localhost:5000/pingReturns: Dogshouseservice.Version1.0.1
Basic:
curl http://localhost:5000/dogsWith sorting:
curl http://localhost:5000/dogs?attribute=weight&order=descWith pagination:
curl http://localhost:5000/dogs?pageNumber=1&pageSize=5All together:
curl http://localhost:5000/dogs?attribute=name&order=asc&pageNumber=1&pageSize=10Parameters:
attribute- sort by: name, color, tail_length, weightorder- asc or desc (default: asc)pageNumber- page number (default: 1)pageSize- how many per page (default: 10)
Response example:
[
{
"name": "Neo",
"color": "red&amber",
"tail_length": 22,
"weight": 32
}
]curl -X POST http://localhost:5000/dog \
-H "Content-Type: application/json" \
-d '{
"name": "Buddy",
"color": "brown",
"tail_length": 15,
"weight": 25
}'Rules:
- Name must be unique
- tail_length must be 0 or positive
- weight must be positive
- All fields required
Errors:
If name already exists:
"Dog with this name already exists"
If tail_length is negative:
"Tail length must be zero or positive"
API allows max 10 requests per second per IP address.
If you send too many requests, you get:
HTTP 429 Too Many Requests
Too many requests. Please try again later.
You can change this in appsettings.json:
{
"RateLimit": {
"RequestsPerSecond": 10
}
}dotnet testAll features are covered by tests.
The app uses Entity Framework with Code First approach.
Initial dogs in database:
- Neo (red&amber, tail: 22, weight: 32)
- Jessy (black&white, tail: 7, weight: 14)
Edit appsettings.json:
{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=DogsHouseDb;Trusted_Connection=True;"
},
"RateLimit": {
"RequestsPerSecond": 10
}
}"Dog with this name already exists" - Try different name
"Tail length must be zero or positive" - Use 0 or positive number
"Too many requests" - Wait 1 second and try again
Database error - Check connection string in appsettings.json