IMPORTANT: THIS REPOSITORY IS OPTIMIZED FOR CODESPACES AND TO WORK AS A SET OF COMPOSABLE APPS AND APIS. STANDALONE PACKAGE FUNCTIONALITY IS LIMITED AND MAY REQUIRE ADDITIONAL CONFIGURATION OR DEVELOPMENT
This package deploys an Azure Functions API that is used by the Contoso Real Estate App, with multiple endpoints, and serving multiple applications, that are part of the scenarios.
IMPORTANT: THIS SCENARIO IS TIGHTLY COUPLED WITH SCENARIO 1. SOME PARTS OF THIS FUNCTION APP MAY NOT WORK AS EXPECTED IF YOU DON'T FOLLOW THE INSTRUCTIONS IN SCENARIO 1. THIS FUNCTION APP QUERIES TWO DATABASES. THEY MAY NEED TO BE IN PLACE IN ORDER FOR THE ENDPOINTS TO WORK
If you want to run the API independently and locally, the following technologies must be in place:
- node.js LTS, with the corresponding npm version
- Azure Core Tools
Azure Functions v4 is the latest version of the Node.js programming model for Azure Functions. It comes with a bunch of new features and improvements, such as:
- Flexible folder structure
- Being able to define function.json directly in the function's in the code
- New HTTP trigger types
- Improved IntelliSense
- Timer Trigger (TypeScript)
- Durable Functions (TypeScript)
- fork or clone the repository locally
- assuming you are in the folder containing your clone, go to the terminal and run
cd packages/api
- create the
local.settings.json
file and add the following block of code:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "node",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing"
}
}
- Now install all the dependencies for the API and run it
npm install && npm start
-
Comment out Stripe in
azure.yaml
anddocker-compose.yml
. -
Start local services in dev container
npm run start:services
- Rename env file for Azure Functions
mv ./packages/api/local.settings.sample.json ./packages/api/local.settings.json
- In new dev container terminal, Build API
npm run start:host --workspace=api
Output should include APIs such as:
Azure Functions Core Tools
Core Tools Version: 4.0.5455 Commit hash: N/A (64-bit)
Function Runtime Version: 4.27.5.21554
[2024-01-04T16:49:20.258Z] Worker process started and initialized.
Functions:
delete-favorites: [DELETE] http://localhost:7071/api/favorites
get-favorites: [GET] http://localhost:7071/api/favorites
get-listings: [GET] http://localhost:7071/api/listings
get-listings-by-id: [GET] http://localhost:7071/api/listings/{id}
get-openapi: [GET] http://localhost:7071/api/{filename?}
get-payments: [GET] http://localhost:7071/api/payments
get-payments-by-id: [GET] http://localhost:7071/api/payments/{id}
get-reservations: [GET] http://localhost:7071/api/reservations
get-reservations-by-id: [GET] http://localhost:7071/api/reservations/{id}
get-users: [GET] http://localhost:7071/api/users
get-users-by-id: [GET] http://localhost:7071/api/users/{id}
patch-reservations-by-id: [PATCH] http://localhost:7071/api/reservations/{id}
post-checkout: [POST] http://localhost:7071/api/checkout
post-favorites: [POST] http://localhost:7071/api/favorites
post-payment: [POST] http://localhost:7071/api/payments
post-users: [POST] http://localhost:7071/api/users
- In new dev container terminal, use cURL to get all listings from PostgreSQL.
curl "http://localhost:7071/api/listings" --verbose
This proves that the API can successfully talk to PostgreSQL.
- Use cURL to favorite a listing for a fake user, adding favorite into MongoDB.
curl -X POST http://localhost:7071/api/favorites -H "Content-Type: application/json" -d '{"listing": {"id": "1"}, "user": {"id": "123"}}' --verbose
- Use cURL to get all favorited items for fake user, querying into MongoDB.
curl "http://localhost:7071/api/favorites?userId=123" --verbose