{"id":21622734,"url":"https://github.com/hyjiacan/restfx","last_synced_at":"2026-03-06T19:35:11.941Z","repository":{"id":136746783,"uuid":"313476638","full_name":"hyjiacan/restfx","owner":"hyjiacan","description":"Python3 的 restful 多应用自动路由框架。此仓库仅作镜像，有疑问请前往 Gitee 仓库。","archived":false,"fork":false,"pushed_at":"2024-03-09T02:33:47.000Z","size":1329,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-25T22:21:51.057Z","etag":null,"topics":["python","restful","wsgi"],"latest_commit_sha":null,"homepage":"https://gitee.com/hyjiacan/restfx/wikis","language":"Python","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hyjiacan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-11-17T01:46:14.000Z","updated_at":"2022-01-07T08:27:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"f92dd650-fbf8-4bd1-94c7-60488d32561e","html_url":"https://github.com/hyjiacan/restfx","commit_stats":null,"previous_names":[],"tags_count":84,"template":false,"template_full_name":null,"purl":"pkg:github/hyjiacan/restfx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyjiacan%2Frestfx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyjiacan%2Frestfx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyjiacan%2Frestfx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyjiacan%2Frestfx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyjiacan","download_url":"https://codeload.github.com/hyjiacan/restfx/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyjiacan%2Frestfx/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30193649,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T19:07:06.838Z","status":"ssl_error","status_checked_at":"2026-03-06T18:57:34.882Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["python","restful","wsgi"],"created_at":"2024-11-25T00:10:00.715Z","updated_at":"2026-03-06T19:35:11.906Z","avatar_url":"https://github.com/hyjiacan.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# restfx\r\n\r\nPython3 的 RESTful 服务框架。\r\n\r\n\u003e 底层基于 [werkzeug](https://werkzeug.palletsprojects.com/)\r\n\r\n## 为什么要使用此框架\r\n\r\n开发此框架的目标是 **提升开发效率**。\r\n\r\n此框架解决了以下问题：\r\n\r\n- 没有繁锁的路由配置，免去路由注册。仅仅需要对模块根进行注册，模块下的所有路由都会自动被收集调用\r\n- 不需要对路由 url 进行显示配置，完全自动解析 \r\n- 自动解析/校验请求参数，并填充到路由函数，省去繁锁的参数获取/类型校验。需要做的仅仅是编写一个函数，并添加函数参数的类型声明 \r\n- 提供 **接口列表页面** 以及接口测试支持，让接口随码更新，不用手动维护API文档。 见[截图](#截图)\r\n- 提供 [路由注入][2] 支持，以通过参数方式向路由指定请求参数外的数据/函数，从而避免一些频繁的 `import` 和重复代码\r\n\r\n**此框架的弊端: 不支持将参数作为 url 路径的一部分**\r\n\r\n## 安装\r\n\r\n```shell script\r\npip install restfx\r\n```\r\n\r\n`Since 0.7.1` 安装后，可以通过 CLI 工具 `restfx` 命令创建基本项目结构:\r\n\r\n```shell script\r\nrestfx create projectname\r\n```\r\n\r\n\u003e 使用此命令，可能需要将 `restfx` 安装到全局环境中。\r\n\r\n## 文档\r\n\r\n使用文档见 [Gitee Wiki][1]\r\n\r\n## 创建应用\r\n\r\n```python\r\nimport os\r\n\r\nimport restfx\r\n\r\nif __name__ == '__main__':\r\n    root = os.path.dirname(__file__)\r\n    app = restfx.App(root, api_prefix='any/prefix', debug=True)\r\n    app.map_routes({\r\n        'x': 'test'\r\n    })\r\n    app.map_static(static_map={})\r\n    app.startup(host='127.0.0.1', port=9127)\r\n```\r\n\r\n### 编写路由\r\n\r\n*test/api/demo.py*\r\n\r\n```python\r\nfrom restfx import route\r\nfrom restfx.http import HttpRequest, HttpFile\r\n\r\n\r\n@route(module='测试名称-模块', name='测试名称-GET')\r\ndef get(request, param1, param2=None, param3: int = 5):\r\n    # request 会是 HttpRequest\r\n    return {\r\n        'param1': param1,\r\n        'param2': param2,\r\n        'param3': param3,\r\n    }\r\n\r\n\r\n@route(module='测试名称-模块', name='测试名称-POST_PARAM')\r\ndef get_param(param1, req: HttpRequest, from_=None, param3=5):\r\n    # req 会是 HttpRequest\r\n    return {\r\n        'param1': param1,\r\n        'from': from_,\r\n        'param3': param3,\r\n    }\r\n\r\n\r\n@route(module='测试名称-模块', name='测试名称-PUT_PARAM')\r\ndef put(request: str, param1, file: HttpFile, param3=5):\r\n    # request 会是请求参数，参数列表中没有 HttpRequest\r\n    return {\r\n        'request': request,\r\n        'param1': param1,\r\n        'param3': param3,\r\n    }\r\n\r\n\r\n@route(module='测试名称-模块', name='测试名称-DELETE_PARAM')\r\ndef delete(request, param1, from_=None, param3=5, **kwargs):\r\n    # 未在函数的参数列表中声明的请求参数，会出现在 kwargs 中\r\n    return {\r\n        'param1': param1,\r\n        'from': from_,\r\n        'param3': param3,\r\n        'variable_args': kwargs\r\n    }\r\n\r\n```\r\n\r\n## 截图\r\n\r\n以下截图为接口列表，对应的路由声明源码见\r\n\r\n- [test/test/api/__init__.py][11]\r\n- [test/test/api/demo.py][12]\r\n\r\n\r\n以下截图仅在 [Gitee仓库目录][3] 可见\r\n\r\n![list](assets/1.png)\r\n\r\n![test](assets/2.png)\r\n\r\n\r\n[1]: https://gitee.com/wangankeji/restfx/wikis\r\n[2]: https://gitee.com/wangankeji/restfx/wikis/0B.%20%E8%B7%AF%E7%94%B1%E6%B3%A8%E5%85%A5?sort_id=3519061\r\n[3]: https://gitee.com/wangankeji/restfx#%E6%88%AA%E5%9B%BE\r\n[11]: https://gitee.com/wangankeji/restfx/blob/master/test/test/api/__init__.py\r\n[12]: https://gitee.com/wangankeji/restfx/blob/master/test/test/api/demo.py\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyjiacan%2Frestfx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyjiacan%2Frestfx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyjiacan%2Frestfx/lists"}