Hotel Listing API
=================
- Build a fully data driven REST Web API using cutting edge technology
- Create a database using Entity Framework Core
- Unit Of Work and Generic Repository Pattern
- Dependency Injection
- Setup Logging using SeriLog
- Setup API documentation using SwaggerUI
- Understand the REST design principles
- Understand C# 9 and .Net Core Web Syntax
- Understand user Authentication using JWT (JSON Web Tokens)
- Understand how to use Data Transfer Objects (DTOs) and AutoMapper
- Manage Packages with NuGet Manager
Table of Contents
Prerequisites
Before you begin, ensure you have the following installed:
-
.NET SDK - To run the application.
-
Visual Studio Code or Visual Studio - For development (optional).
Getting Started
- Clone the repository:
bashCopy code
git clone https://github.com/your-username/hotel-listing-api.git
- Navigate to the project folder:
bashCopy code
cd hotel-listing-api
- Run the application:
bashCopy code
dotnet run
The API should be accessible at https://localhost:5001
or http://localhost:5000
.
API Endpoints
-
Description: Retrieve a list of all countries.
-
Endpoint:
GET /api/country
-
Response:
- 200 OK: Returns a list of countries.
- 500 Internal Server Error: If an error occurs during the process.
-
Description: Retrieve detailed information about a specific country.
-
Endpoint:
GET /api/country/{id}
-
Parameters:
- id
(integer): The ID of the country.
- Response:
- 200 OK: Returns detailed information about the specified country.
- 500 Internal Server Error: If an error occurs during the process.
-
Description: Retrieve a list of all hotels.
-
Endpoint:
GET /api/hotel
-
Response:
- 200 OK: Returns a list of hotels.
- 500 Internal Server Error: If an error occurs during the process.
-
Description: Retrieve detailed information about a specific hotel.
-
Endpoint:
GET /api/hotel/{id}
-
Parameters:
- id
(integer): The ID of the hotel.
- Response:
- 200 OK: Returns detailed information about the specified hotel.
- 500 Internal Server Error: If an error occurs during the process.
Logging
The application utilizes Serilog for logging. Logs are stored in the "logs" folder, and specific logs related to hotel listings are stored in "hotellistingLogs" within the "logs" folder.
Set Jwt Key
-
Open Command Prompt:
- Press
Win + R
to open the Run dialog. - Type
cmd
and pressEnter
to open Command Prompt.
- Press
-
Check Existing Environment Variables (Optional):
- You can check existing environment variables using the
echo %VARIABLE_NAME%
command.
- You can check existing environment variables using the
-
Set JWT Key as Environment Variable:
-
Use the
setx
command to set the JWT key as an environment variable. ReplaceYOUR_JWT_KEY
with your actual JWT key.bashCopy code
setx JWT_KEY "YOUR_JWT_KEY"
-
-
Verify the Environment Variable:
- To verify that the variable has been set, you can use the
echo %JWT_KEY%
command.
- To verify that the variable has been set, you can use the
-
Restart Any Affected Applications (If Necessary):
- Some applications might require a restart to pick up the new environment variable.
-
Confirm Environment Variable Persistence:
- The
setx
command may not affect the current Command Prompt session. Open a new Command Prompt and verify the environment variable usingecho %JWT_KEY%
.
- The
-
Done:
- You have successfully added the JWT key as an environment variable using the
setx
command.
- You have successfully added the JWT key as an environment variable using the
Note:
- Make sure to replace
YOUR_JWT_KEY
with your actual JWT key. - Be cautious while setting environment variables, as they can impact system behavior.
- Use the appropriate syntax and quotes, especially if your JWT key contains spaces or special characters.