- C#
- .Net 6
- ASP.Net Core 6 MVC
- EF Core 6
- SQL
- MySQL
- LINQ
- Swagger
A student project demonstrating knowledge of building RESTful APIs. This is an API is a Parks Lookup: an API for state and national parks. The API will list state and national parks.
- Meet MVP
- [Stretch] Add functionality to call on NPS API to seed db
- [Stretch] Add front end MVC app to consume API
- [Stretch] Add additional endpoint
- ✅ Application includes CRUD functionality and successfully returns responses to API calls.
- ✅ README thoroughly describes all endpoints along with parameters that can be used.
- ✅ Application includes a best effort at implementing at least one of the further exploration objectives: authentication, versioning, pagination, or CORS.
- ✅ README includes specific documentation on further exploration: what it is and how to use it.
- ✅ Build files and sensitive information are included in .gitignore file and is not to be tracked by * Git, and includes instructions on how to create the appsettings.json and set up the project.
- Project is in a polished, portfolio-quality state.
- The prompt’s required functionality and baseline project requirements are in place by the deadline.
- Add a front end MVC application that consumes your API.
- Add a RANDOM endpoint that randomly returns a park/business/animal.
- Add a second custom endpoint that accepts parameters. Example: a SEARCH route that allows users to search by specific park names.
- Navigate to the
ParksApi
directory. - Create a file named
appsettings.json
with the following code. Be sure to update the Default Connection to your MySQL credentials.
{
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Port=3306;database=Api;uid=[YOUR-USERNAME-HERE];pwd=[YOUR-PASSWORD-HERE];"
}
}
- Install dependencies within the
ParksApi
directory
$ dotnet restore
- To build & run program in development mode
$ dotnet run
- To build & run program in production mode
dotnet run --launch-profile "production"
GET http://localhost:5000/api/v2/v2/parks
GET http://localhost:5000/api/v2/parks/{id}
POST http://localhost:5000/api/v2/parks
PUT http://localhost:5000/api/v2/parks/{id}
DELETE http://localhost:5000/api/v2/parks/{id}
Notes:
- The {id} value in the URL is a variable and should be replaced with the id number of the park the user wants to PUT or DELETE
GET http://localhost:5000/api/v2/parks
Returns a collection of parksGET http://localhost:5000/api/v2/parks/{id}
Returns a single park
For GET http://localhost:5000/api/v2/parks
Parameter | Type | Required | Description |
---|---|---|---|
parkType | int | Not Required | Returns parks with matching parkType value (parkType=1 for National, parkType=2 for State) |
State | string | Not Required | Returns parks with matching state value |
City | string | Not Required | Returns parks with matching Y value |
The following query will return all National parks, indicated by the parkType value of 1:
GET http://localhost:5000/api/v2/parks?parkType=1
The following query will return all State parks, indicated by the parkType value of 2:
GET http://localhost:5000/api/v2/parks?parkType=2
The following query will return all parks within a given state, indicated by the state value of "CA":
GET http://localhost:5000/api/v2/parks?state=ca
The following query will return all parks with the city value of "Big Sur":
GET http://localhost:5000/api/v2/parks?city=big sur
It's possible to include multiple query strings by separating them with an &:
GET http://localhost:5000/api/v2/reviews?parkType=1&state=ca
Example:
POST http://localhost:5000/api/v2/parks
{
"name": "Joshua Tree",
"state": "CA",
"city": "Joshua Tree National Park",
"parkTypeId": 1
}
Note: that the value for "parkTypeId" MUST be an int. A value of 1 indicates National Park a value of 2 indicates a State Park.
Example:
PUT http://localhost:5000/api/v2/parks/{id}
{
"parkId": 7,
"name": "Toshua Tree",
"state": "MA",
"city": "Toshua Tree National Park",
"parkTypeId": 1
}
Note: that the value for "parkTypeId" MUST be an int. A value of 1 indicates National Park a value of 2 indicates a State Park.
There are two versions available of the ParksApi. Version 2.0 is the most recent. To revert back to version 1.0, simply replace v2 in the endpoint with v1.
For example:
Version 2.0
GET http://localhost:5000/api/v2/parks
Version 1.0
GET http://localhost:5000/api/v1/parks
- No known bugs. If you find one, please email me at kirsten.opstad@gmail.com with the subject [Repo Name] Bug and include:
- BUG: A brief description of the bug
- FIX: Suggestion for solution (if you have one!)
- If you'd like to be credited, please also include your github user profile link
MIT License
Copyright (c) 2023 Kirsten Opstad
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.