|| US Park API ||
Epicodus - C# and .NET - Building an API - Code Review
___________________________
Jessi B
March 2022
An API that functions as a US Parks archive for national, state and city parks. It utilizes RESTful principles and version control. The user is able to see the in-use version of the API when using Postman.
- Visual Studio Code
- C#
- ASP.NET Core MVC
- MySQL 8.0.20 for Linux
- Entity Framework Core 2.2.6
- Swagger - NSwag 13.3.0
- Postman
- Download Microsoft .NET Core: Mac users click here OR Windows users click here
- Install dotnet script: Enter the command
dotnet tool install -g dotnet-script
in terminal - Install MySQL Workbench: Download and install the appropriate version of MySQL Workbench
- Install Postman: (Optional) Download and install Postman
- Clone Repo: In your terminal, navigate to your desktop or other desired location and enter
git clone https://github.com/jessb-epicodus/USParkAPI.Solution.git
- Add Required Packages: Navigate to the top level of the project directory called USParkAPI & enter each of the following commands:
dotnet add package Microsoft.EntityFrameworkCore -v 5.0.0
dotnet add package Pomelo.EntityFrameworkCore.MySql -v 5.0.0-alpha.2
dotnet add package Microsoft.EntityFrameworkCore.Design -v 5.0.0
dotnet add USParkAPI.csproj package Swashbuckle.AspNetCore -v 6.2.3
dotnet add package Microsoft.AspNetCore.Mvc.Versioning --version 5.0.0
- Protect Your MySQL Password: Enter
touch .gitignore
&touch appsettings.json
in the command line - Add the following code to appsettings.json & update the server, port, and user id & password as necessary:
{ "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } }, "AllowedHosts": "*", "ConnectionStrings": { "DefaultConnection": "Server=localhost;Port=3306;database=US_park;uid=root;pwd=YOUR PASSWORD;" } }
- Add */appsettings.json to .gitignore
- Update Database: Enter
dotnet ef migrations add <MigrationName>
&dotnet ef database update
in the terminal - Install Dependecies: Enter
dotnet restore
in your terminal - Try Out This Web App: Enter
dotnet run
in the command line and either,- Navigte to http:https://localhost:5000/ in Postman - or -
- Navigate to http:https://localhost:5000/swagger in your browser
- HTTP Requests
- GET /api/parks
- POST /api/parks
- GET /api/parks/{id}
- PUT /api/parks/{id}
- DELETE /api/parks/{id}
- Endpoints: Use base URL: https://localhost:5000
- Example Query: https://localhost:5000/api/parks
- Sample JSON Response:
{
"parkId": 5,
"name": "Molalla River Recreation Area",
"city": "Molalla",
"state": "Oregon",
"managedBy": "Bureau of Land Management",
"activities": "fishing",
"amenities": "restrooms",
"ada": true
}
Parameter | Type | Default | Required | Description |
---|---|---|---|---|
name | string | none | required | Return matches by name |
city | string | none | required | Return matches by city |
state | string | none | required | Return matches by state |
managedBy | string | none | required | Return matches by who manages the park |
activities | string | none | required | Return matches by activities |
amenities | string | none | required | Return matches by amenities |
ada | bool | none | required | Return matches if true |
- Example Query: https://localhost:5000/api/parks?state=oregon&state=portland
- Sample JSON Response
{
"parkId": 5,
"name": "Forest Park",
"city": "Portland",
"state": "Oregon",
"managedBy": "Portland Parks and Recreation",
"activities": "trail running",
"amenities": "",
"ada": true
}
This is not a real API, which is the greatest shame of all.
Copyright (c) Mar 2022 Jessi B
If you run into any issues or have questions, ideas or concerns or wish to make a contribution to the code see contact information below.
- Jessi B [email protected]
Return to Top