- Configure Environment Variable
MSSQL_CONNECTION_STRING
or supply a file named./secrets-store/MSSQL_CONNECTION_STRING
- Run the app:
gunicorn --bind=0.0.0.0 --workers=4 startup:app
- Populate Data:
- Either go to: http://localhost:8000/setup
- Or invoke the Rest API:
Invoke-RestMethod -Uri 'http://localhost:8000/api/setup' -Method Post -Body '{ "drop_schema" : true, "create_schema": true, "populate_data" : true }' -ContentType 'application/json'
- Build the Docker Image:
docker build -t pycontosohotel:latest .
- Run the Docker Container:
- Using environment variable
docker run -p 8000:8000 -e MSSQL_CONNECTION_STRING='DRIVER={ODBC Driver 18 for SQL Server};SERVER=MSSQLINSTANCENAME.database.windows.net;DATABASE=MSSQLDBNAME;UID=MSSQLUSERNAME;PWD=*******' pycontosohotel:latest
- Using volume mount
- Create a file
MSSQL_CONNECTION_STRING
with the connection string in the/path/to/secrets-store
directory docker run -p 8000:8000 -v '/path/to/secrets-store:/app/secrets-store' pycontosohotel:latest
- Create a file
- Using environment variable
- Populate Data:
- Either go to: http://localhost:8000/setup
- Or invoke the Rest API:
Invoke-RestMethod -Uri 'http://localhost:8000/api/setup' -Method Post -Body '{ "drop_schema" : true, "create_schema": true, "populate_data" : true }' -ContentType 'application/json'
Endpoint: GET /api/hotels
Get Parameter | Type | Default Value | Description |
---|---|---|---|
hotelname |
string | empty | Optional Hotel Name to filter |
exactMatch |
bool | false | Optional exactMatch (false uses like '%search%' ) |
Response Codes:
Code | Description |
---|---|
200 | Success |
400 | Bad Request (Invalid input data) |
500 | Internal Server Error (Server side processing error) |
Example Response Body (Success - 200):
[
{
"hotelId": 6,
"hotelname": "Contoso Hotel Los Angeles",
"pricePerNight": 350.0
}
]
Example Response Body (Failure - 400 or 500):
{
"success" : false,
"error" : "Some error message here"
}
Click to expand
Invoke-RestMethod -Uri 'http://localhost:8000/api/hotels'
curl -X GET 'http://localhost:8000/api/hotels'
Endpoint: GET /api/visitors
Get Parameter | Type | Default Value | Description |
---|---|---|---|
name |
string | empty | Optional Name to filter (first or last name) |
exactMatch |
bool | false | Optional exactMatch (false uses like '%search%' ) |
Response Codes:
Code | Description |
---|---|
200 | Success |
400 | Bad Request (Invalid input data) |
500 | Internal Server Error (Server side processing error) |
Example Response Body (Success - 200):
[
{
"firstname": "Frank",
"lastname": "Green",
"visitorId": 6
}
]
Example Response Body (Failure - 400 or 500):
{
"success" : false,
"error" : "Some error message here"
}
Click to expand
Invoke-RestMethod -Uri 'http://localhost:8000/api/visitors'
curl -X GET 'http://localhost:8000/api/visitors'
Endpoint: GET /api/bookings
Get Parameter | Type | Default Value | Description |
---|---|---|---|
visitorId |
int | empty | Optional visitorId to filter |
hotelId |
int | empty | Optional hotelId to filter |
fromdate |
datetime (YYYY-MM-DD) | empty | Optionally filter for bookings that are after this date |
untildate |
datetime (YYYY-MM-DD) | empty | Optionally filter for bookings that are before this date |
Response Codes:
Code | Description |
---|---|
200 | Success |
400 | Bad Request (Invalid input data) |
500 | Internal Server Error (Server side processing error) |
Example Response Body (Success - 200):
[
{
"bookingId": 2,
"checkin": "2024-07-05",
"checkout": "2024-07-10",
"hotelId": 2,
"hotelname": "Contoso Hotel Paris",
"visitorId": 2,
"firstname": "Bob",
"lastname": "Jones",
"adults": 2,
"kids": 0,
"babies": 0,
"rooms": 1,
"price": 1000.0
}
]
Example Response Body (Failure - 400 or 500):
{
"success" : false,
"error" : "Some error message here"
}
Click to expand
Invoke-RestMethod -Uri 'http://localhost:8000/api/bookings'
curl -X GET 'http://localhost:8000/api/bookings'
Endpoint: GET /api/hotel?hotelId=<int>
Response Codes:
Code | Description |
---|---|
200 | Success |
400 | Bad Request (Invalid input data) |
500 | Internal Server Error (Server side processing error) |
Example Response Body (Success - 200):
{
"hotelId": 6,
"hotelname": "Contoso Hotel Los Angeles",
"pricePerNight": 350.0
}
Example Response Body (Failure - 400 or 500):
{
"success" : false,
"error" : "Some error message here"
}
Click to expand
Invoke-RestMethod -Uri 'http://localhost:8000/api/hotel?hotelId=2'
curl -X GET 'http://localhost:8000/api/hotel?hotelId=2'
Endpoint: GET /api/visitor?visitorId=<int>
Response Codes:
Code | Description |
---|---|
200 | Success |
400 | Bad Request (Invalid input data) |
500 | Internal Server Error (Server side processing error) |
Example Response Body (Success - 200):
{
"firstname": "Frank",
"lastname": "Green",
"visitorId": 6
}
Example Response Body (Failure - 400 or 500):
{
"success" : false,
"error" : "Some error message here"
}
Click to expand
Invoke-RestMethod -Uri 'http://localhost:8000/api/visitor?visitorId=2'
curl -X GET 'http://localhost:8000/api/visitor?visitorId=2'
Endpoint: GET /api/booking?bookingId=<int>
Response Codes:
Code | Description |
---|---|
200 | Success |
400 | Bad Request (Invalid input data) |
500 | Internal Server Error (Server side processing error) |
Example Response Body (Success - 200):
{
"bookingId": 2,
"visitorId": 6,
"hotelId": 2,
"checkin": "2024-07-05",
"checkout": "2024-07-10",
"rooms": 1,
"adults": 2,
"kids": 0,
"babies": 0,
"price": 1000.0
}
Example Response Body (Failure - 400 or 500):
{
"success" : false,
"error" : "Some error message here"
}
Click to expand
Invoke-RestMethod -Uri 'http://localhost:8000/api/booking?bookingId=2'
curl -X GET 'http://localhost:8000/api/booking?bookingId=2'
Endpoint: PUT /api/hotel
Request Body:
{
"hotelname": "Contoso Hotel Los Angeles",
"pricePerNight": 350.0
}
Response Codes:
Code | Description |
---|---|
200 | Success |
400 | Bad Request (Invalid input data) |
500 | Internal Server Error (Server side processing error) |
Example Response Body (Success - 200):
{
"hotelId": 6,
"hotelname": "Contoso Hotel Los Angeles",
"pricePerNight": 350.0
}
Example Response Body (Failure - 400 or 500):
{
"success" : false,
"error" : "Some error message here"
}
Click to expand
Invoke-RestMethod -Uri 'http://localhost:8000/api/hotel' -Method Put -ContentType 'application/json' -Body (@{
hotelname = 'Contoso Hotel Los Angeles II'
pricePerNight = 350.0
} | ConvertTo-Json)
curl -X PUT 'http://localhost:8000/api/hotel' -H 'Content-Type: application/json' -d '{
"hotelname": "Contoso Hotel Los Angeles II",
"pricePerNight": 350.0
}'
Endpoint: PUT /api/visitor
Request Body:
{
"firstname": "Frank",
"lastname": "Green"
}
Response Codes:
Code | Description |
---|---|
200 | Success |
400 | Bad Request (Invalid input data) |
500 | Internal Server Error (Server side processing error) |
Example Response Body (Success - 200):
{
"visitorId": 6,
"firstname": "Frank",
"lastname": "Green"
}
Example Response Body (Failure - 400 or 500):
{
"success" : false,
"error" : "Some error message here"
}
Click to expand
Invoke-RestMethod -Uri 'http://localhost:8000/api/visitor' -Method Put -ContentType 'application/json' -Body (@{
firstname = 'Frank'
lastname = 'Blue'
} | ConvertTo-Json)
curl -X PUT 'http://localhost:8000/api/visitor' -H 'Content-Type: application/json' -d '{
"firstname": "Frank",
"lastname": "Blue"
}'
Endpoint: PUT /api/booking
Request Body:
{
"visitorId": 6,
"hotelId": 2,
"checkin": "2024-07-05",
"checkout": "2024-07-10",
"adults": 2,
"kids": 0, // optional
"babies": 0, // optional
"rooms": 1, // optional
"price": 1000.0 // optional
}
Response Codes:
Code | Description |
---|---|
200 | Success |
400 | Bad Request (Invalid input data) |
500 | Internal Server Error (Server side processing error) |
Example Response Body (Success - 200):
{
"bookingId": 2,
"visitorId": 6,
"hotelId": 2,
"checkin": "2024-07-05",
"checkout": "2024-07-10",
"rooms": 1,
"adults": 2,
"kids": 0,
"babies": 0,
"price": 1000.0
}
Example Response Body (Failure - 400 or 500):
{
"success" : false,
"error" : "Some error message here"
}
Click to expand
Invoke-RestMethod -Uri 'http://localhost:8000/api/booking' -Method Put -ContentType 'application/json' -Body (@{
visitorId = 6
hotelId = 2
checkin = '2025-07-05'
checkout = '2025-07-10'
adults = 2
kids = 0
babies = 0
rooms = 1
price = 1000.0
} | ConvertTo-Json)
curl -X PUT 'http://localhost:8000/api/booking' -H 'Content-Type: application/json' -d '{
"visitorId": 6,
"hotelId": 2,
"checkin": "2025-07-05",
"checkout": "2025-07-10",
"adults": 2,
"kids": 0,
"babies": 0,
"rooms": 1,
"price": 1000.0
}'
Endpoint: POST /api/hotel
Request Body:
{
"hotelId": 6,
"hotelname": "Contoso Hotel Los Angeles",
"pricePerNight": 350.0
}
Response Codes:
Code | Description |
---|---|
200 | Success |
400 | Bad Request (Invalid input data) |
500 | Internal Server Error (Server side processing error) |
Example Response Body (Success - 200):
{
"hotelId": 6,
"hotelname": "Contoso Hotel Los Angeles",
"pricePerNight": 350.0
}
Example Response Body (Failure - 400 or 500):
{
"success" : false,
"error" : "Some error message here"
}
Click to expand
Invoke-RestMethod -Uri 'http://localhost:8000/api/hotel' -Method Post -ContentType 'application/json' -Body (@{
hotelId = 6
hotelname = 'Contoso Hotel Los Angeles'
pricePerNight = 350.0
} | ConvertTo-Json)
curl -X POST 'http://localhost:8000/api/hotel' -H 'Content-Type: application/json' -d '{
"hotelId": 6,
"hotelname": "Contoso Hotel Los Angeles",
"pricePerNight": 350.0
}'
Endpoint: POST /api/visitor
Request Body:
{
"visitorId": 6,
"firstname": "Frank",
"lastname": "Green"
}
Response Codes:
Code | Description |
---|---|
200 | Success |
400 | Bad Request (Invalid input data) |
500 | Internal Server Error (Server side processing error) |
Example Response Body (Success - 200):
{
"visitorId": 6,
"firstname": "Frank",
"lastname": "Green"
}
Example Response Body (Failure - 400 or 500):
{
"success" : false,
"error" : "Some error message here"
}
Click to expand
Invoke-RestMethod -Uri 'http://localhost:8000/api/visitor' -Method Post -ContentType 'application/json' -Body (@{
visitorId = 6
firstname = 'Frank'
lastname = 'Green'
} | ConvertTo-Json)
curl -X POST 'http://localhost:8000/api/visitor' -H 'Content-Type: application/json' -d '{
"visitorId": 6,
"firstname": "Frank",
"lastname": "Green"
}'
Endpoint: DELETE /api/hotel?hotelId=<int>
Url Parameter | Type | Default Value | Description |
---|---|---|---|
hotelId |
int | empty | Required id of the hotel |
Response Codes:
Code | Description |
---|---|
200 | Success |
400 | Bad Request (Invalid input data) |
500 | Internal Server Error (Server side processing error) |
Example Response Body (Success - 200):
{
"success": true,
"deleted": true, // indicates if deletion was necessary
"hotelId": 6
}
Example Response Body (Failure - 400 or 500):
{
"success" : false,
"error" : "Some error message here"
}
Click to expand
Invoke-RestMethod -Uri 'http://localhost:8000/api/hotel?hotelId=2' -Method Delete
curl -X DELETE 'http://localhost:8000/api/hotel?hotelId=2'
Endpoint: DELETE /api/visitor?visitorId=<int>
Url Parameter | Type | Default Value | Description |
---|---|---|---|
visitorId |
int | empty | Required id of the visitor |
Response Codes:
Code | Description |
---|---|
200 | Success |
400 | Bad Request (Invalid input data) |
500 | Internal Server Error (Server side processing error) |
Example Response Body (Success - 200):
{
"success": true,
"deleted": true, // indicates if deletion was necessary
"visitorId": 6
}
Example Response Body (Failure - 400 or 500):
{
"success" : false,
"error" : "Some error message here"
}
Click to expand
Invoke-RestMethod -Uri 'http://localhost:8000/api/visitor?visitorId=2' -Method Delete
curl -X DELETE 'http://localhost:8000/api/visitor?visitorId=2'
Endpoint: DELETE /api/booking?bookingId=<int>
Url Parameter | Type | Default Value | Description |
---|---|---|---|
bookingId |
int | empty | Required id of the booking |
Response Codes:
Code | Description |
---|---|
200 | Success |
400 | Bad Request (Invalid input data) |
500 | Internal Server Error (Server side processing error) |
Example Response Body (Success - 200):
{
"success": true,
"deleted": true, // indicates if deletion was necessary
"bookingId": 2
}
Example Response Body (Failure - 400 or 500):
{
"success" : false,
"error" : "Some error message here"
}
Click to expand
Invoke-RestMethod -Uri 'http://localhost:8000/api/booking?bookingId=2' -Method Delete
curl -X DELETE 'http://localhost:8000/api/booking?bookingId=2'
Endpoint: POST /api/setup
Request Body:
{
"drop_schema" : false,
"create_schema": true,
"populate_data": true
}
Response Codes:
Code | Description |
---|---|
200 | Success |
400 | Bad Request (Invalid input data) |
500 | Internal Server Error (Server side processing error) |
Example Response Body (Success - 200):
{
"success": true,
"drop_schema": false,
"create_schema": {
"hotels": false,
"visitors": false,
"bookings": true
},
"populate_data": {
"hotels": false,
"visitors": true,
"bookings": true
}
}
Example Response Body (Failure - 400 or 500):
{
"success" : false,
"error" : "Some error message here"
}
Click to expand
Invoke-RestMethod -Uri 'http://localhost:8000/api/setup' -Method Post -ContentType 'application/json' -Body (@{
drop_schema = $true
create_schema = $true
populate_data = $true
} | ConvertTo-Json)
curl -X POST 'http://localhost:8000/api/setup' -H 'Content-Type: application/json' -d '{
"drop_schema": true,
"create_schema": true,
"populate_data": true
}'