python+vue3内嵌html实现一个类似postman的api调试工具代码
代码语言:python
所属分类:其他
代码描述:python+vue3内嵌html实现一个类似postman的api调试工具代码
代码标签: python vue 内嵌 htm 类似 postman api 调试 工具 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
#!/usr/local/python3/bin/python3
# -*- coding: utf-8 -*
import requests
import json
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse, JSONResponse
from pydantic import BaseModel
from typing import Any, Dict, Optional, List
# 1. FastAPI 应用实例
app = FastAPI(
title="API Debugger Pro",
description="A simple Postman-like API debugger built with FastAPI and Vue.js",
)
# 2. Pydantic 模型更新
# 更通用的键值对模型,可用于Header和Form
class KeyValueItem(BaseModel):
key: str
value: str
class ProxyRequest(BaseModel):
method: str
url: str
headers: Optional[List[KeyValueItem]] = []
# 新增字段以区分body类型
body_type: str = 'none' # 'none', 'json', 'form'
json_body: Optional[str] = None
form_body: Optional[List[KeyValueItem]] = []
# 3. HTML, CSS, 和 Vue.js 前端代码 (已更新)
HTML_TEMPLATE = """
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>API Debugger Pro</title>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/vue.global.3.2.37.js"></script>
<style>
:root {
--bg-color: #1a1a1a; --panel-color: #242424; --text-color: rgba(255, 255, 255, 0.87);
--primary-color: #646cff; --border-color: #535bf2; --input-bg: #1e1e1e;
--status-ok: #42d392; --status-error: #ff6961; --status-info: #ffc107;
}
*, *::before, *::after { box-sizing: border-box; }
body {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
margin: 0; background-color: var(--bg-color); color: var(--text-color);
font-synthesis: none; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased;
}
#ap.........完整代码请登录后点击上方下载按钮下载查看















网友评论0