Skip to main content

ApiResult

Type Alias ApiResult 

Source
pub type ApiResult<T> = Result<T, ApiError>;
Expand description

Result for JSON handlers: errors become ApiError JSON responses.

§Examples

use axum::extract::{Path, State};
use ocre::{ApiResult, Ctx, Json, OptionExt, params};

async fn show(State(ctx): State<Ctx>, Path(id): Path<i64>) -> ApiResult<Json<serde_json::Value>> {
    let post = ctx.db()?.first("SELECT * FROM posts WHERE id = ?1", params![id]).await?.or_404()?;
    Ok(Json(post))
}

Aliased Type§

pub enum ApiResult<T> {
    Ok(T),
    Err(ApiError),
}

Variants§

§1.0.0

Ok(T)

Contains the success value

§1.0.0

Err(ApiError)

Contains the error value