Skip to content
Flydo edited this page Mar 1, 2025 · 5 revisions

开发

# 格式化
cargo fmt

# 检测
cargo fmt -- --check

构建

  1. 安装 sqlx
cargo install sqlx-cli
  1. 设置环境变量
source ../.env
  1. 创建数据库
sqlx database create
  1. 创建数据表
sqlite3 url_shortener.db < migrations/schema.sql
  1. 查看表
sqlite3 url_shortener.db ".tables;
  1. 测试运行
cargo run
  1. 构建
cargo build --release

使用

创建短链

curl -X POST http://127.0.0.1:3000/shorten -d '{"url": "https://github.com/forkdo/shorturl"}' -H "Content-Type: application/json"

结果

{"short_url":"http://localhost:3000/3a088213"}

Clone this wiki locally