Kuí
An easy-to-use web framework. Based on baize and pydantic.
Install
pip install kui
An easy-to-use web framework. Supports both WSGI and ASGI modes. Gevent or asyncio, this is the question.
Home Page: https://kui.aber.sh
License: Apache License 2.0
#12 在这里我实现了基于 Radix Tree 的路由。
为了这口醋,我再去包一锅饺子不太好,并且 index.py 有许多地方与 IndexFile 不是强耦合的。考虑更改默认的路由机制为列表申明式与装饰器式。IndexFile 作为 Application 存在,通过 mount 组合进行请求处理。这样既可以保持 php 风格的文件映射,又可以让路由更加灵活的应对不同需求。
Related link: https://developer.mozilla.org/zh-CN/docs/Web/HTTP/CORS
Minimum Example
from indexpy import Index, Body
app = Index()
@app.router.http.post("/")
def test(param: str = Body()):
return dict(error=param)
当固定路由与动态路由冲突时,如果预测动态路由会先匹配则直接抛出错误,如果预测固定路由先匹配,则如故。
使用默认值为类型增加描述是妥协的做法。
async def function(name: name: Annotated[type, Query(**options)]) -> Annotated[Any, PlainTextResponse[200]]:
return name
Query[type, options]
使用这种方式,编辑器支持不会很好。因为不能传关键词,所以 options 要么是一个充满 None 的序列,要么是一个字典。写起来都不会太舒服。
Translate Chinese documents to English and deploy.
@routes.http("/path", middlewares=[.................])
def f(): ...
@routes.websocket("/path", middlewares=[.................])
def f(): ...
使用 index.py 编写一个网站,用作新手教程。
在某些情况下需要如下例代码来同时注册 "/user"
和 "/user/login"
两个路由。故而仅允许 ""
不以 "/"
开头。
"/user" // Routes(
HttpRoute("", ......),
HttpRoute("/login", ......),
)
在根上的 ""
跟随浏览器行为,自动转换为 "/"
路由。即 app.router << HttpRoute("", ......)
等价于 app.router << HttpRoute("/", ......)
from indexpy.routing.tree import RadixTree
t = RadixTree()
def donothing():
pass
def donothing2():
pass
# 交换下面两个路由的顺序,断言可以通过
t.append("/app/{hello}/", donothing)
t.append("/app/hello/", donothing2)
ret = t.search("/app/world/")
print(ret) # ({'hello': 'world'}, <function donothing at 0x7f12c94931f0>)
assert ret[1] == donothing
ret = t.search("/app/hello/")
print(ret) # ({'hello': 'hello'}, <function donothing at 0x7f12c94931f0>)
assert ret[1] == donothing2
期望的行为应该类似于 flask 如下:
curl xxxx/a1/hello/ ==> hello2
curl xxxx/a1/world/ ==> hello1
from flask import Flask
app = Flask(__name__)
@app.route("/a1/<hello>/")
def hello1(hello):
return "hello1"
@app.route("/a1/hello/")
def hello2():
return "hello2"
app.run()
另外这里
检查路由冲突的地方
第 60 行的 if (node.re_pattern == re_pattern) != (node.characters == param_name):
会不会有 re_pattern 不同, 而 characters == param_name 相同的情况?(这一块没太看懂)
将 indexpy.config.Config
从 indexpy.application.Index
等程序中抽离,改用普通参数进行配置。去除中间件配置,需要主动导入中间件并自行配置。
保留 Config,但仅用于 index-cli
。
由于 Starlette 本身现在更像是一个框架而不是一个工具箱,并且 encode 团队似乎没有太多的时间维护这个框架,更多的精力都在 httpx 上。所以直接放弃使用 Starlette,转而使用 BaíZé 进行重构。除部分响应类外,大部分接口仍然可以保持一致。并且相较于 Starlette,BaíZé 有更丰富的功能支持,比如文件响应允许分片、更加完善的响应类泛型。
自定义异常处理——>示例代码当中需要from indexpy.types import Request, Response
但是最新版当中indexpy.types没有Request和Response
这是对增加拓展性的必须路程。但或许会带来 PHP 一样的任意路径代码执行问题。
使用类固然使局部代码更加紧凑,但是也牺牲了使用的便捷性。遂决定增加使用的函数的注册方式,原有注册方式保持不变。
在 *.py
文件中未寻找到 HTTP
对象,则寻找如下名称的函数作为对应 HTTP 请求方法的处理函数:"get", "post", "put", "patch", "delete", "head", "options", "trace"。这意味着使用时不需要继承 indexpy.HttpView
,直接定义一个名为 get
的异步函数即可处理请求。
在内部代码里,使用 MultimethodRoutes 同等方式,合并多个函数到一个类中。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.