project1 / frontend /test2.py
rssaem
start ..
290381f
Raw
History Blame Contribute Delete
829 Bytes
import streamlit as st
import requests
st.title("Streamlit ๋ฐฑ์—”๋“œ ํ†ต์‹  ์˜ˆ์ œ (GET)")
# ๋ฐฑ์—”๋“œ API URL
#API_URL = "http://localhost:8000/api/data"
API_URL = "https://jsonplaceholder.typicode.com/posts"
if st.button("๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ"):
try:
# ๋ฐฑ์—”๋“œ์— GET ์š”์ฒญ ๋ณด๋ƒ„
response = requests.get(API_URL)
if response.status_code == 200:
data = response.json()
st.success("๋ฐ์ดํ„ฐ๋ฅผ ์„ฑ๊ณต์ ์œผ๋กœ ๊ฐ€์ ธ์™”์Šต๋‹ˆ๋‹ค!")
st.json(data) # Notion์ด๋‚˜ ํ™”๋ฉด์— ๊น”๋”ํ•˜๊ฒŒ JSON ์ถœ๋ ฅ
else:
st.error(f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {response.status_code}")
except requests.exceptions.ConnectionError:
st.error("๋ฐฑ์—”๋“œ ์„œ๋ฒ„์— ์—ฐ๊ฒฐํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ์„œ๋ฒ„๊ฐ€ ์ผœ์ ธ ์žˆ๋Š”์ง€ ํ™•์ธํ•˜์„ธ์š”.")