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("๋ฐฑ์—”๋“œ ์„œ๋ฒ„์— ์—ฐ๊ฒฐํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ์„œ๋ฒ„๊ฐ€ ์ผœ์ ธ ์žˆ๋Š”์ง€ ํ™•์ธํ•˜์„ธ์š”.")