File size: 829 Bytes
290381f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 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("๋ฐฑ์๋ ์๋ฒ์ ์ฐ๊ฒฐํ ์ ์์ต๋๋ค. ์๋ฒ๊ฐ ์ผ์ ธ ์๋์ง ํ์ธํ์ธ์.") |