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("백엔드 서버에 연결할 수 없습니다. 서버가 켜져 있는지 확인하세요.")