Refactor: HttpClient usage; update deployment docs - #6
Conversation
- Use AddHttpClient<T> for all service registrations to avoid shared HttpClient timeout issues - Add Microsoft.Extensions.Http package and centralize version - Clarify in docs that env vars are set on Azure Function App, not Static Web App - Cross-reference n8n workflow setup in application settings - Improve deployment checklist formatting and backend steps
WalkthroughChangesTyped HTTP client wiring
Azure deployment documentation
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Program
participant AppointmentService
participant DownstreamAPI
Program->>AppointmentService: Register typed HttpClient with BaseAddress
AppointmentService->>DownstreamAPI: Send service-specific HTTP request
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/02-deployment/AZURE_FUNCTION_DEPLOYMENT.md`:
- Line 187: Update the N8N_WEBHOOK_URL documentation entry to state that an
unset value causes BookAppointmentFunction.cs to return HTTP 500 instead of HTTP
502. Preserve the existing production URL, activation requirement, database
configuration, and workflow setup guidance.
In `@docs/02-deployment/DEPLOYMENT_CHECKLIST.md`:
- Line 38: Update the deployment checklist item to describe the system-assigned
Managed Identity enabled on the Function App and its Key Vault access, removing
the inaccurate reference to linking it with the Static Web App.
In `@Program.cs`:
- Around line 105-106: Update the typed HTTP client registrations for
AppointmentService, ApiEmailService, ChatbotService, and ResumeService to use
their configured ApiBaseUrl values instead of
builder.HostEnvironment.BaseAddress. Resolve the first three base addresses from
each service’s “{Service}:ApiBaseUrl” configuration entry, and configure
ResumeService with the absolute ResumeUrl.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: d5811664-7b25-4dee-a44b-0ed2f668e8bf
📒 Files selected for processing (6)
CloudZen.csprojDirectory.Packages.propsProgram.csdocs/02-deployment/AZURE_FUNCTION_DEPLOYMENT.mddocs/02-deployment/DEPLOYMENT_CHECKLIST.mddocs/02-deployment/DEPLOYMENT_GUIDE.md
| | `BREVO_SMTP_KEY` | `your-brevo-smtp-key` | Brevo SMTP relay key | | ||
| | `BREVO_SMTP_LOGIN` | `your-smtp-login@smtp-brevo.com` | Brevo SMTP login | | ||
| | `N8N_WEBHOOK_URL` | `https://cloudzen-n8n.pikapod.net/webhook/appointments` | n8n appointment booking webhook — Production URL only, workflow must be activated (required — 502 if unset). Booking DB (Neon Postgres) is configured inside n8n itself, not an Azure resource. | | ||
| | `N8N_WEBHOOK_URL` | `https://cloudzen-n8n.pikapod.net/webhook/appointments` | n8n appointment booking webhook — Production URL only, workflow must be activated (required — 502 if unset). Booking DB (Neon Postgres) is configured inside n8n itself, not an Azure resource. See [../08-N8N/appointment-system-v3.md](../08-N8N/appointment-system-v3.md) for workflow setup. | |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Correct the missing-configuration status code.
BookAppointmentFunction.cs returns HTTP 500 when N8N_WEBHOOK_URL is unset, not 502. Update the description to prevent incorrect incident diagnosis.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@docs/02-deployment/AZURE_FUNCTION_DEPLOYMENT.md` at line 187, Update the
N8N_WEBHOOK_URL documentation entry to state that an unset value causes
BookAppointmentFunction.cs to return HTTP 500 instead of HTTP 502. Preserve the
existing production URL, activation requirement, database configuration, and
workflow setup guidance.
| - [ ] Set `ANTHROPIC_API_KEY` in Azure Function App settings | ||
| - [x] Backend created and deployed (`CloudZen.Api`, Consumption plan) — see [AZURE_FUNCTION_DEPLOYMENT.md](AZURE_FUNCTION_DEPLOYMENT.md) for setup | ||
| - [x] `SendEmailFunction.cs` and `ChatFunction.cs` deployed | ||
| - [x] Managed Identity enabled, linked to Static Web App |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Correct the Managed Identity relationship.
The deployment guide documents a system-assigned identity on the Function App with Key Vault access; it does not establish a Managed Identity link to the Static Web App. Reword this item to reflect the actual Function App/Key Vault configuration.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@docs/02-deployment/DEPLOYMENT_CHECKLIST.md` at line 38, Update the deployment
checklist item to describe the system-assigned Managed Identity enabled on the
Function App and its Key Vault access, removing the inaccurate reference to
linking it with the Static Web App.
| builder.Services.AddHttpClient<IAppointmentService, AppointmentService>(client => | ||
| client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
rg -n -C 6 \
'class (AppointmentService|ResumeService|ApiEmailService|ChatbotService)|ApiBaseUrl|BaseAddress|GetAsync|PostAsync|SendAsync' \
--glob '*.cs'Repository: MyTeamForDev/CloudZen
Length of output: 159
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
echo "== tracked .cs Program.cs files =="
git ls-files '*.cs' | rg '/Program\.cs$|Program\.cs$' || true
echo
echo "== all .cs files with service/client/base/url terms =="
rg -n -i -C 4 \
'AddHttpClient|BaseAddress|ApiBaseUrl|appointment|resume|email|chatbot|GetAsync|PostAsync|SendAsync|HttpClient' \
--glob '*.cs' . || trueRepository: MyTeamForDev/CloudZen
Length of output: 50378
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Program.cs relevant section =="
sed -n '80,135p' Program.cs | cat -n
echo
echo "== service implementation files =="
for f in \
Program.cs \
Features/Contact/Services/ApiEmailService.cs \
Features/Chat/Services/ChatbotService.cs \
Features/Profile/Services/ResumeService.cs
do
if [ -f "$f" ]; then
echo "--- $f ---"
git ls-files | rg "(\b|\bAppointments/Services/AppointmentService.cs)\b" | head -20
fi
done
echo
echo "== Http methods and BaseAddress/ApiBaseUrl usage in tracked .cs files =="
rg -n \
'AddHttpClient<I(AppointmentService|ResumeService|ApiEmailService|ChatbotService)|IProjectService)|HttpClient|BaseAddress|CreateFromApiBase|Get.*AsJsonAsync|Send.*Async|Post.*AsJsonAsync|ChatUrl|SendEmailUrl|ResumeUrl|ApiBaseUrl' \
--glob '*.cs' \
| head -200Repository: MyTeamForDev/CloudZen
Length of output: 7166
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
import re, pathlib
root=pathlib.Path('.')
terms='|'.join([
r'builder\.Services\.AddHttpClient<',
r'\.BaseAddress\s*=',
r'ApiBaseUrl',
r'ChatUrl|SendEmailUrl',
r'Get.*AsJsonAsync|Post.*AsJsonAsync|Send.*Async',
r'GetByteArrayAsync',
])
regex=re.compile(terms)
for path in root.rglob('*.cs'):
text=path.read_text(errors='ignore')
if not regex.search(text):
continue
print(f'\n## {path}')
for i,line in enumerate(text.splitlines(),1):
if regex.search(line):
print(f'{i:4}: {line}')
services=[
'Features/Contact/Services/ApiEmailService.cs',
'Features/Chat/Services/ChatbotService.cs',
'Features/Profile/Services/ResumeService.cs',
]
for svc in services:
p=pathlib.Path(svc)
print(f'\n## {p} relevant methods')
lines=p.read_text(errors='ignore').splitlines()
for start,end in [(1,80),(80,170),(170,230)]:
text='\n'.join(lines[s-1:e])
if any(s in text for s in ['PostAsJsonAsync','GetByteArrayAsync','DeleteAsync','string url']):
print(f'--- lines {start}-{end} ---')
print(text)
PY
echo
echo "== find AppointmentService files =="
git ls-files | rg 'Appointment(Service|s).*\.cs$|Appointments/Services' || trueRepository: MyTeamForDev/CloudZen
Length of output: 4282
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
for svc in [
"Features/Booking/Services/AppointmentService.cs",
"Features/Contact/Services/ApiEmailService.cs",
"Features/Chat/Services/ChatbotService.cs",
"Features/Profile/Services/ResumeService.cs",
]:
p=Path(svc)
if not p.exists():
print(f"MISSING {svc}")
continue
text=p.read_text(errors="ignore")
print(f"\n## {p}")
start=len(text)
for meth in ["CreateFromApiBase", "SendAsync", "PostAsJsonAsync", "GetByteArrayAsync"]:
idx=text.find(meth)
if idx>=0 and idx<start:
start=idx
print(text[start:start+1200])
PY
echo
echo "== deterministic Uri/BaseAddress behavior =="
python3 - <<'PY'
from urllib.parse import urljoin
host='https://app.example/'
local='http://localhost:7257/api'
for path in ['/api', 'api/', '/api/send-email']:
print(path, 'with host BaseAddress ->', urljoin(host, path))
print(path, 'with local BaseAddress ->', urljoin(local, path))
PY
echo
echo "== check SendAsJsonAsync extension signature/source availability =="
rg -n "CreateFromApiBase|IAppointmentService|AddHttpClient<IAppointmentService|localUrl|functionsLocalUrl|ApiBaseUrl" Program.cs Features/Booking Features/Contact Features/Chat Features/Profile --glob '*.cs'Repository: MyTeamForDev/CloudZen
Length of output: 7526
Configure the typed HTTP clients from the local functions URL.
builder.Configuration["{Service}:ApiBaseUrl"] = functionsLocalUrl is set, but the typed clients override BaseAddress to builder.HostEnvironment.BaseAddress. Since AppointmentService sends relative requests and ApiEmailService/ChatbotService compose endpoint paths from ApiBaseUrl, these requests will be routed to the WebAssembly origin in development. Set each typed client’s BaseAddress from its ApiBaseUrl; use the absolute ResumeUrl for ResumeService.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@Program.cs` around lines 105 - 106, Update the typed HTTP client
registrations for AppointmentService, ApiEmailService, ChatbotService, and
ResumeService to use their configured ApiBaseUrl values instead of
builder.HostEnvironment.BaseAddress. Resolve the first three base addresses from
each service’s “{Service}:ApiBaseUrl” configuration entry, and configure
ResumeService with the absolute ResumeUrl.
Refactor: HttpClient usage; update deployment docs
Summary by CodeRabbit
Bug Fixes
Documentation