/TravelApi.Solution

C# program: Travel API

Primary LanguageC#

Travel Review API

practice building an API

By: Michelle Morin, Joseph Wangemann, Jonathan Carlos, Kristina Hengster Tintor, March 30-April 2, 2020

Description

This API allows users to GET, POST, PUT, and DELETE reviews about various travel destinations around the world.

Specification user stories:

  • A user is able to GET and POST reviews about travel destinations.
  • A user is able to GET reviews by country, city, or destination name. Reviews are returned in order of highest to lowest rating.
  • A user is able to see the most popular travel destinations by overall rating.
  • A user is able to PUT and DELETE reviews.
  • A user is able to receive a JSON web token (expires 1 day after issuance) by sending a valid username and password in a POST request to '/users/authenticate'. Web tokens are not currently used to authenticate user requests to GET/POST/PUT/DELETE reviews.

Setup/Installation Requirements

Install .NET Core

on macOS:

  • Click here to download a .NET Core SDK from Microsoft Corp.
  • Open the file (this will launch an installer which will walk you through installation steps. Use the default settings the installer suggests.)

on Windows:

  • Click here to download the 64-bit .NET Core SDK from Microsoft Corp.
  • Open the .exe file and follow the steps provided by the installer for your OS.

Install dotnet script

Enter the command dotnet tool install -g dotnet-script in Terminal (macOS) or PowerShell (Windows).

Install MySQL

on macOS:

Download the MySQL Community Server DMG File here. Follow along with the installer until you reach the configuration page. Once you've reached Configuration, set the following options (or user default if not specified):

  • use legacy password encryption
  • set password (and change the password field in appsettings.json file of this repository to match your password)
  • click finish
  • open Terminal and enter the command echo 'export PATH="/usr/local/mysql/bin:$PATH"' >> ~/.bash_profile if using Git Bash.
  • Verify MySQL installation by opening Terminal and entering the command mysql -uroot -p{your password here, omitted brackets}. If you gain access to the MySQL command line, installation is complete. An error (e.g., -bash: mysql: command not found) indicates something went wrong.

on Windows:

Download the MySQL Web Installer here and follow along with the installer. Click "Yes" if prompted to update, and accept license terms.

  • Choose Custom setup type
  • When prompted to Select Products and Features, choose the following: MySQL Server (Will be under MySQL Servers) and MySQL Workbench (Will be under Applications)
  • Select Next, then Execute. Wait for download and installation (can take a few minutes)
  • Advance through Configuration as follows:
    • High Availability set to Standalone.
    • Defaults are OK under Type and Networking.
    • Authentication Method set to Use Legacy Authentication Method.
    • Set password to epicodus. You can use your own if you want but epicodus will be assumed in the lessons.
    • Unselect Configure MySQL Server as a Windows Service.
  • Complete installation process

Add the MySQL environment variable to the System PATH. Instructions for Windows 10:

  • Open the Control Panel and visit System > Advanced System Settings > Environment Variables...
  • Select PATH..., click Edit..., then Add.
  • Add the exact location of your MySQL installation and click OK. (This location is likely C:\Program Files\MySQL\MySQL Server 8.0\bin, but may differ depending on your specific installation.)
  • Verify installation by opening Windows PowerShell and entering the command mysql -uroot -p{your password here, omitted brackets}. It's working correctly if you gain access to the MySQL command line. Exit MySQL by entering the command exit.

Clone this repository

Enter the following commands in Terminal (macOS) or PowerShell (Windows):

  • cd desktop
  • git clone followed by the URL to this repository
  • cd TravelApi.Solution/TravelApi

Confirm that you have navigated to the TravelApi directory (e.g., by entering the command pwd in Terminal).

Recreate the travel database using the following commands (in Terminal on macOS or PowerShell on Windows) at the root of the TravelApi directory:

  • dotnet restore
  • dotnet build
  • dotnet ef database update

Run this application by entering the following command in Terminal (macOS) or PowerShell (Windows) at the root of the TravelApi directory:

  • dotnet run or dotnet watch run
  • access the Swagger UI for testing this API

To view/edit the source code of this application, open the contents of the TravelApi.Solution directory in a text editor or IDE of your choice (e.g., to open all contents of the directory in Visual Studio Code on macOS, enter the command code . in Terminal at the root of the TravelApi.Solution directory).

Technologies Used

  • Git
  • C#
  • dotnet script
  • MySQL
  • Entity Framework Core 2.2
  • RestSharp version 106.6.10
  • Newtonsoft.Json version 12.0.2
  • Swagger 3.0 documentation (swagger.json)
  • NSwag
  • JSON Web Token Authentication

License

Licensed under the MIT license.

© 2020 - Michelle Morin, Joseph Wangemann, Jonathan Carlos, Kristina Hengster Tintor