Last updated
Last updated
+ Protocol json--------------------------------+
|+ handler -----------------------------------+|
||file :/handlers/{app}/__init__.py:{handler}||
||return:(stat_str, data_dict, headers_list) ||
|+--------------------------------------------+|
| return:httpstatus, headers, content |
+----------------------------------------------+
HTTP 请求方法
HTTP 响应状态码及 Content-Type:
当需要序列化为 JSON 时, HTTP 状态码均为 200, 响应内容类型均为 ("Content-Type", "application/json"):
检查参数错误时,返回 {"stat": "ERR_BAD_PARAMS"}
程序执行异常时,返回 {"stat": "ERR_SERVER_EXCEPTION"}
+ Protocol file--------------------------------+
|+ handler -----------------------------------+|
||file :/handlers/{app}/__init__.py:{handler}||
||return:(stat_str, data_dict, headers_list) ||
|+--------------------------------------------+|
| return:httpstatus, headers, content |
+----------------------------------------------+
HTTP 请求方法:
仅支持 GET 方法(仅用于获取文件)
HTTP 响应状态码及 Content-Type:
HTTP 响应状态码:
文件不存在时,HTTP 状态码为 404
文件没读权限时,HTTP 状态码为 403
检查参数错误时,HTTP 状态码为 400
程序执行异常时,HTTP 状态码为 500
HTTP 响应 Content-Type:
文件 is_download 为 True 时,会根据文件后缀名进行识别文件类型
文件 is_download 为 False 时,响应内容类型均为 ("Content-Type", "text/html")
from xlib.httpgateway import Request
from xlib import retstat
from xlib.middleware import funcattr
__info = "api_demo"
__version = "1.0.1"
@funcattr.api_download
def download(req):
"""
Args:
req : (Object) Request
Returns:
stat_str, content_dict, headers_list
> stat_str : (String)
> content_dict : (Dict)
filename : (String) 文件路径
is_download : (Bool) 是否需要下载
> headers_list : (List)
key 和 value 都需要是 str 类型
"""
isinstance(req, Request)
return retstat.OK, {"filename": "test/static_file/test_html.html", "is_download": True}, [(__info, __version)]
from xlib.httpgateway import Request
from xlib import retstat
from xlib.middleware import funcattr
__info = "api_demo"
__version = "1.0.1"
@funcattr.api_upload
def upload(req):
"""
"""
# 处理请求 body
return retstat.OK, {}, []