42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
async function testAPI() {
|
|
console.log("1. Requesting Token for jayam_web_ai...");
|
|
|
|
const tokenResponse = await fetch("http://localhost:8080/v1/auth/token", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
grant_type: "client_credentials",
|
|
client_id: "jayam_web_ai",
|
|
client_secret: "my_secret_key"
|
|
})
|
|
});
|
|
|
|
const tokenData = await tokenResponse.json();
|
|
|
|
if (!tokenData.access_token) {
|
|
console.error("Failed to get token!", tokenData);
|
|
return;
|
|
}
|
|
|
|
console.log("✅ Successfully received real JWT token!");
|
|
console.log("Token:", tokenData.access_token.substring(0, 30) + "...\n");
|
|
|
|
console.log("2. Using Token to search for drugs (Catalogue API)...");
|
|
|
|
const searchResponse = await fetch("http://localhost:8080/v1/drugs/search?q=Losartan", {
|
|
method: "GET",
|
|
headers: {
|
|
"Authorization": `Bearer ${tokenData.access_token}`,
|
|
"X-Actor-Id": "usr_ph_1234"
|
|
}
|
|
});
|
|
|
|
const searchData = await searchResponse.json();
|
|
|
|
console.log(`✅ API Response Status: ${searchResponse.status}`);
|
|
console.log("Drug Search Results:");
|
|
console.log(JSON.stringify(searchData, null, 2));
|
|
}
|
|
|
|
testAPI();
|