There was an error while loading. Please reload this page.
# 格式化 cargo fmt # 检测 cargo fmt -- --check
sqlite3 url_shortener.db < migrations/schema.sql
sqlite3 url_shortener.db ".tables"; sqlite3 url_shortener.db ".schema urls";
cargo run
cargo build --release
查看服务
$ curl http://127.0.0.1:3000/ Short URL Service
创建短链
$ curl -X POST http://127.0.0.1:3000/shorten -d '{"url": "https://github.com/forkdo/shorturl"}' -H "Content-Type: application/json" {"short_code":"6ef212fa","short_url":"http://localhost:3000/6ef212fa"}
查看短链
$ curl -I http://localhost:3000/6ef212fa HTTP/1.1 307 Temporary Redirect location: https://github.com/forkdo/shorturl content-length: 0 date: Tue, 04 Mar 2025 10:55:09 GMT
获取短链
$ curl http://localhost:3000/get/6ef212fa {"short_code":"6ef212fa","original_url":"https://github.com/forkdo/shorturl"}