| import streamlit as st |
| import requests |
|
|
| st.title("Streamlit ๋ฐฑ์๋ ํต์ ์์ (GET)") |
|
|
| |
| |
| API_URL = "https://jsonplaceholder.typicode.com/posts" |
|
|
| if st.button("๋ฐ์ดํฐ ๋ถ๋ฌ์ค๊ธฐ"): |
| try: |
| |
| response = requests.get(API_URL) |
| |
| if response.status_code == 200: |
| data = response.json() |
| st.success("๋ฐ์ดํฐ๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ๊ฐ์ ธ์์ต๋๋ค!") |
| st.json(data) |
| else: |
| st.error(f"์ค๋ฅ ๋ฐ์: {response.status_code}") |
| |
| except requests.exceptions.ConnectionError: |
| st.error("๋ฐฑ์๋ ์๋ฒ์ ์ฐ๊ฒฐํ ์ ์์ต๋๋ค. ์๋ฒ๊ฐ ์ผ์ ธ ์๋์ง ํ์ธํ์ธ์.") |