{"id":22014113,"url":"https://github.com/laqudee/rust_web_server","last_synced_at":"2026-04-13T11:02:03.787Z","repository":{"id":146793067,"uuid":"611808031","full_name":"laqudee/rust_web_server","owner":"laqudee","description":"Rust + Actix + PostgresSQL 构建的WebService","archived":false,"fork":false,"pushed_at":"2023-03-16T12:26:15.000Z","size":56,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T08:30:03.693Z","etag":null,"topics":["actix","postgres","rest-api","rust","webservice"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/laqudee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-03-09T15:32:48.000Z","updated_at":"2023-03-23T08:29:31.000Z","dependencies_parsed_at":"2023-04-09T04:33:15.682Z","dependency_job_id":null,"html_url":"https://github.com/laqudee/rust_web_server","commit_stats":{"total_commits":15,"total_committers":1,"mean_commits":15.0,"dds":0.0,"last_synced_commit":"b212d95aef0ed31d1319bf5786a201048a54f11a"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/laqudee/rust_web_server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laqudee%2Frust_web_server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laqudee%2Frust_web_server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laqudee%2Frust_web_server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laqudee%2Frust_web_server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/laqudee","download_url":"https://codeload.github.com/laqudee/rust_web_server/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laqudee%2Frust_web_server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31749763,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-13T09:16:15.125Z","status":"ssl_error","status_checked_at":"2026-04-13T09:16:05.023Z","response_time":93,"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":["actix","postgres","rest-api","rust","webservice"],"created_at":"2024-11-30T03:26:23.503Z","updated_at":"2026-04-13T11:02:03.766Z","avatar_url":"https://github.com/laqudee.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Actix的基本组件\n\n- 设备浏览器通过互联网 到达Actix HTTP Server（包含Actix APP） 访问 Actix Route 找到 Actix Handler\n- Actix Handler 返回资源到设备浏览器\n\n\n## Actix 的并发\n- 异步I/O：给定的OS原生线程在等待I/O时执行其他任务；例如侦听网络连接\n- 多线程并行：默认情况下启动OS原声线程的数量与系统逻辑CPU数量相同\n\n\n# 构建的内容\n\nPOST A Course \u003c---\u003e Handler 1 ---\u003e db_access 1\n\nGET A Course \u003c---\u003e Handler 2 ---\u003e db_access 2\n\nGET all course for teacher \u003c---\u003e Handler 3 ---\u003e db_access 3\n\n## 具体\n- POST: /courses\n- GET: /courses/teacher_id\n- GET: /courses/teacher_id/course_id\n\n## Test\n\n```shell\ncurl -x POST localhost:3000/courses/ -H \"Content-Ty\npe: application/json\" -d '{\"teacher_id\":1, \"name\":\"First course\"}'\n```\n\n# 连接数据库\n\n- sqlx\n- PostgreSQL\n\n# 错误处理\n\n- 数据库错误\n- seder错误（串行化）\n- I/O错误\n- Actix错误\n- 用户非法输入错误\n\n- 上述错误通过自定义错误类型，转为 HTTP Response 错误\n\n## 错误处理方式\n- 异常\n- 返回值（rust 使用这种）\n\n## Actix-Web把错误转化为 HTTP Response\n\n- actix_web::error::Error\n  - 实现了std::error::Error这个trait\n  - 这个trait，实现了常见错误内置\n    - rust 标准 i/o错误\n    - serde错误\n    - web错误\n    - 其他错误类型\n\n- 任何实现了标准库Error trait的类型，都可以通过?运算符，转化为 Actix的 Error类型\n\n- Actix的Error类型会自动的转化为 HTTP Response 返回给客户\n\n## 创建自定义错误处理器\n1. 创建一个自定义错误类型\n2. 实现From trait，用于把其他错误类型转化为该类型\n3. 为自定义错误类型实现ResponseError trait\n4. 在handler里返回自定义错误类型\n5. Actix会把错误转化为HTTP响应\n\n# Web App\n\n- 模板引擎：Tera\n\n- actix-files：处理静态文件\n- awc：相当于一个http客户端\n\n# WebAssembly\n\n- 新的编码方式，可以在现代浏览器中运行\n  - 低级的类汇编语言\n  - 具有紧凑的二进制格式\n  - 可以接近原生的性能\n  - 并为C/C++，Rust提供一个编译目标\n  - 被设计为可与JS共存，一起工作\n\n- 文本格式\n- 二进制格式\n\n## WebAssembly可以做什么？\n\n- 把Rust编译为WebAssembly\n\n- 快速，高效，可移植\n- 可读\n- 安全\n- 不破坏网络\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaqudee%2Frust_web_server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaqudee%2Frust_web_server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaqudee%2Frust_web_server/lists"}