爲了方便查看, 先在這裡拉一個表格出來。
| 返回碼 | 命名 | 備注 |
| 202 | Accepted | |
| 400 | Bad Request | |
| 409 | Conflict | |
| 201 | Created | |
| Custom | 自定義返回碼 | |
| 403 | For bidden | |
| 204 | No Content | |
| 401 | Unauthorized |
自定義返回狀態碼樣例
這裡寫了一個get網站根目錄之後返回個攜帶418狀態碼, 同時body裡帶個json字符串。
#[derive(Responder)]
#[response(status = 418, content_type = "json")]
struct RawTeapotJson(&'static str);
#[get("/")]
fn json() -> RawTeapotJson {
RawTeapotJson("{ \"hi\": \"world\" }")
}注意這裡的Json不是那個serde::json::Json
想返回200怎麽辦?
官方文档上說應當: Empty with given status. 就是什麽Status都別寫。