python+nicegui实现类似postman'的http的api接口可视化调试工具代码

代码语言:python

所属分类:web系统

代码描述:python+nicegui实现类似postman'的http的api接口可视化调试工具代码

代码标签: python nicegui 类似 postman http api 接口 可视化 调试 工具 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

from nicegui import ui, app
import httpx
import json
import time
import uuid
from datetime import datetime

# ================= 配置与状态管理 =================
class ApiState:
    def __init__(self):
        self.url = 'https://jsonplaceholder.typicode.com/todos/1'
        self.method = 'GET'
        # 存储源数据为 JSON 字符串
        self.headers = '{\n  "Content-Type": "application/json"\n}'
        self.body = '{\n  \n}'
        self.response_content = ''
        self.response_meta = {'status': '-', 'time': '-', 'size': '-'}
        self.history = []

state = ApiState()

# ================= 主页面逻辑 =================
@ui.page('/')
def main_page():
    # 样式配置
    ui.colors(primary='#5898d4', secondary='#26a69a', accent='#9c27b0', dark='#1d1d1d')
    ui.query('body').classes('bg-gray-900 text-gray-200')

    # -------------------------------------------------------
    #  组件占位符
    # -------------------------------------------------------
    resp_editor = None
    left_drawer = None
    
    # -------------------------------------------------------
    #  通用组件:Key-Value 编辑器 (支持 Raw/UI 切换)
    # -------------------------------------------------------
    class KeyValueEditor:
        def __init__(self, target_attr, label):
            self.target_attr = target_attr # 'headers' or 'body'
            self.label = label
            self.is_raw = False # 默认为可视化模式
            self.rows = [] # 格式: [{'id': uuid, 'key': '...', .........完整代码请登录后点击上方下载按钮下载查看

网友评论0