API made for Epicodus to demonstrate understanding of API creation in ASP.net core mvc using SQL with Entity framework and Swagger Documentation
ABOUT
This API is designed to collect and display all of Portland, Oregon's finest restaurants and shops. It can be utilized with a front-end application such as .NET MVC, or queried independently.
- Install Git v2.62.2+
- Install .NET version 3.1 SDK v2.2+
- Install Visual Studio Code
- Install MySql Workbench
- Install Postman
copy this url to clone this project to your local system:
https://github.com/jhenager/PortlandBusiness.Solution.git
Once copied, select "Clone Repository" from within VSCode & paste the copied link.
With the project open to the root directory, navigate to the production directory with the following command in your terminal.
cd PortlandBusiness
Then, install the necessary packages with the following command
dotnet restore
Finally, you can start the program with this command.
dotnet run
Next we will need to setup our MySql database for the application to work.
First, you will need to update the username and password in the appsettings.json file to match your local username and password. Replace the word "root" with your username, and the word "epicodus" with your password. Be sure to leave the "u" and "p" in there as they stand for username and password respectively.
Because the project already has migrations and seeded data, all you will need to do is update the database.
dotnet ef database update
touch .gitignore
ni .gitignore
DO NOT PROCEED UNTIL YOU DO!
node_modules/
.DS_store
dist/
appsettings.json
bin/
obj/
git add .gitignore
git commit -m "protect data"
First we are going to start a localhost server in the PortlandBusiness project folder. In the command line enter:
dotnet watch run
Once the project has built, Open Postman and Click on the plus sign in the middle of the page (or the plus sign that says "New" in the corner).
To get all of either the Restaurants or Shops in this API and view them enter "http://localhost5000/api/restaurants" or "http://localhost5000/api/shops" respectively into the search bar with "GET" selected on the dropdown. Results will look like:
[
{
"restaurantId": 1,
"name": "Ground Kontrol",
"type": "Bar",
"description": "Downtown Arcade Bar"
},
{
"restaurantId": 2,
"name": "Laurelhurst Market",
"type": "Steakhouse",
"description": "Restaurant and Deli providing fine meats"
},
{
"restaurantId": 3,
"name": "Soro Soro",
"type": "Dessert",
"description": "Korean desserts and coffee drinks"
},
To get one particular Restaurant or Shop in this API and view them enter "http://localhost5000/api/restaurants/1" or "http://localhost5000/api/shops/1" respectively into the search bar with "GET" selected on the dropdown. The "1" in the url can be replaced with any other number to retrieve the object with that ID. Click Send, results will look like:
{
"restaurantId": 1,
"name": "Ground Kontrol",
"type": "Bar",
"description": "Downtown Arcade Bar"
},
To add an entry to either the Restaurants or Shops in this API enter "http://localhost5000/api/restaurants" or "http://localhost5000/api/shops" respectively into the search bar with "Post" selected on the dropdown. Before clicking send, click on the tab marked body, the click on the radio button that saws raw. Paste the following into the body, replace the values with the values you wish and click send.
{
"restaurantId": 0,
"name": "string",
"type": "string",
"description": "string"
}
To edit an entry in either Restaurants or Shops in this API enter "http://localhost5000/api/restaurants/1" or "http://localhost5000/api/shops/1" respectively into the search bar with "Put" selected on the dropdown. Replace the "1" with the id of the entry you would like to edit. Before clicking send, click on the tab marked body, the click on the radio button that saws raw. Paste the following into the body, replace the values with the values you wish and click send.
{
"restaurantId": 0,
"name": "string",
"type": "string",
"description": "string"
}
To add an entry to either the Restaurants or Shops in this API enter "http://localhost5000/api/restaurants/1" or "http://localhost5000/api/shops/1" respectively into the search bar with "Delete" selected on the dropdown. Replace the "1" with the id of the entry you would like to delete. Click send to delete the entry.
To view all of the API's endpoint documentation with swagger, first make sure a live server is running. If it isn't, navigate into the PortlandBusiness project folder in the command line and enter:
dotnet watch run
Then in your web browser, navigate to "http://localhost5000/swagger"
Click on each tab and experiment with the "try it out" button to see how the different endpoints function.
Questions, comments and concerns can be directed to James Henager (jameschenager@gmail.com)
Written in: Visual Studio Code
Database Mgmt: MySql Workbench