A web API made utilizing C#, .NET5, MySQL, and Entity that contains a database for all the National Parks in the United States. The API uses authentication for POST requests, requiring users who have an account to make POST requests.
- Preview
- Technologies Used
- Description
- Setup/Installation Requirements
- Additional Setup/Installation Note for Windows Users
- Specifications
- Known Bugs
- License
- Contact Information
- C# 8.0
- .NET 5 Framework
- ASP.NET Core
- MVC 2.2
- MySQL + MySQL Workbench -v 8.0.15
- RESTful Routing
- CRUD Functionality
- Git
- Microsoft Visual Studio Code
- Entity
-
For the API Authentication, I used Token-based JSON Authentication, or JWT. The user is required to have their login information in the List in line 15 of JwtAuthenticationManager.cs (for the time being). JWT is based access token created for claims. It's a self-contained and compact standard for access token to securely transfer claims.
-
In ASP.Net Core, the authentication middleware is added in the Startup class, inside the Configure method. It is done by calling UseAuthentication method on the IApplicationBuilder instance passed to the method.
Authentication schemes are registered in the Startup class inside of the ConfigureServices method. It's done by calling AddAuthentication method on the IServiceCollection instance passed to the method.
For this project, I used JWT. For creating a JWT, one can use different hash algorithms. I used HS256 algorithm for this project.
-
Open terminal.
-
Install Microsoft .NET Version 5.
-
Clone this project with the following git command
$ git clone https://github.com/kdrendel99/National-Parks-API.git
-
Open project using your preferred code editor.
-
Create appsettings.json in ParksAPI.Solution/ParksAPI, and add this code into it:
{ "ConnectionStrings": { "DefaultConnection": "Server=localhost;Port=3306;database=Firstname_Lastname;uid=root;pwd=[YOUR-PASSWORD-HERE];" } }
-
Navigate to ParksAPI.Solution/ParksAPI
-
Enter 'dotnet restore' into terminal and press enter to restore dependencies.
-
Enter 'dotnet ef database update' into the terminal to create local database from migration.
-
Enter 'dotnet run' into terminal, and run the project.
-
Retrieves all National Parks from the database. All 63 National Parks are available to all with GET requests.
-
An example query. Follow the GET all endpoint with '?' + the category you want to filter by, =, and what you'd like to query for. The query also works with the Main Attraction category, and you can search for activities/places such as "shipwreck", "hiking", "Old Faithful", etc. You can categorize your query with the following filters: 'parkId', 'name', 'state', and 'attraction'.
-
Search by Park Id (alphabetized by park name, 1-63).
To make a POST request, the user must be on the authentication list (note: create user functionality and database containing users are not yet built). For beta version POST functionality, follow the steps below
-
In Postman, set your endpoint to http://localhost:5000/api/name/authenticate
-
Click on the Body tab below the endpoint search bar, and enter the following:
{"username":"testUser1", "password": "password1"}
-
Ensure the input type is set to JSON, and send the post request.
-
In the return, you'll receive your API token. Save this for the next step.
-
Navigate to either of the GET request endpoints, and click on the Authorization tab under the endpoint box.
-
Select 'Bearer Token', and paste your token in the token box on the right.
-
In the body box, format your post request in the following way for POST, DELETE, or PUT:
{
"parkId": 63,
"name": "Zion",
"state": "Utah",
"mainAttraction": "Sandstone formations, and the Virgin River"
}
- No way to create new users for authorization.
- User permission/authenticate list is stored in a List type instead of an encripted database (very low security)
-
Copyright <2021> Karlson Drendel
-
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.
Copyright (c) 2021 Karlson Drendel
Karlson Drendel [email protected]