Prj2 / test_api.ps1
iitmbs24f's picture
Upload 37 files
2f95553 verified
# PowerShell script to test the API correctly
# Usage: .\test_api.ps1
# Set variables if not already set
if (-not $env:QUIZ_SECRET) {
$env:QUIZ_SECRET = "EasyQuiz"
}
# Create the request body as a PowerShell object (not a string)
$body = @{
email = "24f2005753@ds.study.iitm.ac.in"
secret = "EasyQuiz"
url = "https://tds-llm-analysis.s-anand.net/demo"
} | ConvertTo-Json
Write-Host "Sending request to /solve endpoint..." -ForegroundColor Cyan
Write-Host "Body: $body" -ForegroundColor Gray
Write-Host ""
try {
$response = Invoke-RestMethod `
-Uri "http://127.0.0.1:8000/solve" `
-Method POST `
-ContentType "application/json" `
-Body $body
Write-Host "Response:" -ForegroundColor Green
$response | ConvertTo-Json -Depth 10
}
catch {
Write-Host "Error occurred:" -ForegroundColor Red
Write-Host $_.Exception.Message -ForegroundColor Red
if ($_.ErrorDetails.Message) {
Write-Host "Details:" -ForegroundColor Yellow
Write-Host $_.ErrorDetails.Message -ForegroundColor Yellow
}
if ($_.Response) {
$reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
$responseBody = $reader.ReadToEnd()
Write-Host "Response Body:" -ForegroundColor Yellow
Write-Host $responseBody -ForegroundColor Yellow
}
}