1 Star 1 Fork 0

axumrs / todo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

使用axum构建todo服务

本专题将带你从零开始实现一个简单的、RESTFUL 风格的 Todo 服务。包括:JSON 响应及请求、PostgreSQL 的使用、自定义错误的处理、RESTFul 的定义、配置文件、日志的记录等。

在此之前,我们强烈建议你先阅读《漫游 axum》。

模型

我们的 Todo 服务分为两个模型:

  • TodoList:待办事项

  • TodoItem:待办事项的项目

API

我们的 Todo 服务提供以下 API:

请求方式 路由 说明
GET /todo 所有 TodoList
POST /todo 为指定的 TodoList 添加 Item
GET /todo/:list_id 获取 TodoList 详情
DELETE /todo/:list_id 删除指定的 TodoList 及其 Item
PUT /todo/:list_id 修改 TodoList
GET /todo/:list_id/items 获取 TodoList 关联的 Item
GET /todo/:list_id/items/:item_id 获取 TodoList 关联的某个 Item 详情
PUT /todo/:list_id/items/:item_id 修改 TodoList 关联的某个 Item 详情
DELETE /todo/:list_id/items/:item_id 删除 TodoList 关联的某个 Item 详情

准备工作

开始之前,请先创建 PostgreSQL,并导入以下 SQL 语句:

DROP TABLE IF EXISTS todo_item;
DROP TABLE IF EXISTS todo_list;


CREATE TABLE todo_list(
    id SERIAL PRIMARY KEY,
    title VARCHAR(150) NOT NULL
);

CREATE TABLE todo_item(
    id SERIAL PRIMARY KEY,
    title VARCHAR(150) NOT NULL,
    checked BOOLEAN NOT NULL DEFAULT FALSE,
    list_id INTEGER NOT NULL,
    FOREIGN KEY(list_id) REFERENCES todo_list(id)
);

INSERT INTO todo_list (title) VALUES ('清单1'), ('清单2');

INSERT INTO todo_item (title, list_id) VALUES
    ('清单项目 1', 1),
    ('清单项目 2', 1),
    ('清单项目 A', 2);

代码

本专题代码可以在axumrs/todo找到。并且,每一章节的代码都以独立分支形式提供。

MIT License Copyright (c) 2021-present AXUM.RS Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

使用AXUM构建TODO服务 展开 收起
Rust 等 2 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/axumrs/todo.git
git@gitee.com:axumrs/todo.git
axumrs
todo
todo
main

搜索帮助

53164aa7 5694891 3bd8fe86 5694891