- C#
- ASP.NET Core MVC v6.0
- Swagger
- MySQL
- Postman
- Visual Studio Code + the C# Dev Kit Extension: ms-dotnettools.csdevkit
This API returns information about various recreation areas through an API.
- You'll need the .NET SDK installed on your system to run the app. Downloads for the .NET SDK are available here.
- Install dotnet-ef globally to enable databse migrations using the following command
$ dotnet tool install --global dotnet-ef --version 6.0.0
- For further database migration assistance, this lesson from learnhowtoprogram.com is helpful.
- Clone the repository git clone https://github.com/aaronvbrown/ParkFinderAPI.Solution.git in the terminal
- Navigate to this project's production directory "ParkFinderAPI"
- Create a file appsettings.json, adding the following code. (Replace uid and pwd with your own username and password for MySQL)
{ "ConnectionStrings": { "DefaultConnection": "Server=localhost;Port=3306;database=aaron_brown;uid=[your-username];pwd=[your-password];" } }
- Run dotnet ef database update from the command line to create a database locally that the project can use.
- Run dotnet run in the command line to start the app
- Run dotnet watch run in the command line to load in development mode with a watcher
- A swagger web page is configured to open showing api endpoints here: https://localhost:5000/swagger/index.html
- Interact with the API using Postman via https://localhost:5000
The base URL is: https://localhost:5000
GET /api/{component}
POST /api/{component}
GET /api/{component}/{id}
PUT /api/{component}/{id}
DELETE /api/{component}/{id}
- Parks
http://localhost:5000/api/Parks
(GET, POST)
http://localhost:5000/api/Parks/1
(GET, PUT, DELETE)
[
{
"parkId": 1,
"name": "Yellowstone",
"state": "Montana",
"type": "National Park"
},
{
"parkId": 2,
"name": "Crater Lake",
"state": "Oregon",
"type": "National Park"
}
]
Request Body:
{
"name": "Mt St Helens",
"state": "Washington",
"type": "National Monument"
}
Response Body:
{
"parkId": 6,
"name": "Mt St Helens",
"state": "Washington",
"type": "National Monument"
}
{
"parkId": 1,
"name": "Yellowstone",
"state": "Montana",
"type": "National Park"
}
Request Body:
{
"parkId":1,
"name":"Yellowrock",
"state":"Montana",
"type":"National Park"
}
The API should return a Status 204 No Content response. Verify update results with a GET request for the appropriate parkId.
GET /api/{component}/?{parameter}={value}
Parameter | Data Type | Required/Optional | Description |
---|---|---|---|
name | string | optional | complete name of park (ex. {Crater Lake}, {Yellowstone}) |
state | string | optional | complete name of state (ex. {Rhode Island}, {Oregon}) |
type | string | optional | complete type of park (ex. {National Park}, {National Monument}) |
PageSize | int | optional | number of results per page ( defaults to 2, max 3 ) |
PageNumber | int | optional | page number requested (defaults to 1) |
Filter results of the Parks index GET request using the above structure.
Example: http://localhost:5000/api/Parks/?type=National Park
Chain filters together using & to separate the key=value pairs:
Example: http://localhost:5000/api/Parks/?state=washington&PageNumber=2
- Pagination via the "pagination" branch is now working as of 12/3/2023.
- Please report any bugs at the github repo issues page
- Pagination was implemented for this project.
- The default page number returned is 1.
- The default page size is 2 and the max page size is 3.
MIT License
Copyright (c) 2023 Aaron Brown