Skip to main content

Api

Struct Api 

Source
pub struct Api<'a, D> { /* private fields */ }
Expand description

Server-side endpoint calls. Pass the request’s headers (or a session token) for endpoints that need a session.

Implementations§

Source§

impl<D: Adapter> Api<'_, D>

Source

pub fn adapter(&self) -> &D

The configured adapter.

Source

pub fn within(self, db: D, events: &DeferredEvents) -> Self

Runs every call on db instead of the configured adapter (its queries, session lookup, hooks and gates), and queues the calls’ events on events instead of firing them.

Each call runs inside its own db.begin(), committed when the call succeeds and rolled back when it fails, so a failed call leaves db as it was. That needs an adapter whose begin nests inside its own queries: with sqlx, use .in_tx(&tx) from fastauth_sqlx::InTx, which binds the adapter to a transaction and makes begin a savepoint.

Source

pub fn headers(self, headers: &HeaderMap) -> Self

Uses these request headers: cookies for the session, user agent and so on.

Source

pub fn session_token(self, token: &str) -> Self

Acts as the session with this raw token.

Source

pub async fn call<E: Endpoint<D>>( &self, endpoint: &E, input: E::Input, ) -> Result<ApiResponse<E::Output>, AuthError>

Runs any endpoint, with its access check, hooks and events.

Source

pub async fn create_user( &self, input: CreateUserInput, ) -> Result<UserView, AuthError>

Creates a user, plus a credential account when password is set. Server-only: there is no HTTP route. Validates like sign-up and answers USER_ALREADY_EXISTS (422) when the email is taken.

Source

pub async fn sign_up_email( &self, input: SignUpEmailInput, ) -> Result<ApiResponse<SignUpOutput>, AuthError>

Source

pub async fn sign_in_email( &self, input: SignInEmailInput, ) -> Result<ApiResponse<SignInOutput>, AuthError>

Source

pub async fn sign_out(&self) -> Result<ApiResponse<SignOutOutput>, AuthError>

Source

pub async fn list_sessions( &self, ) -> Result<ApiResponse<Vec<Map<String, Value>>>, AuthError>

Source

pub async fn revoke_other_sessions( &self, ) -> Result<ApiResponse<Status>, AuthError>

Source

pub async fn change_password( &self, input: ChangePasswordInput, ) -> Result<ApiResponse<ChangePasswordOutput>, AuthError>

Source

pub async fn request_password_reset( &self, input: RequestPasswordResetInput, ) -> Result<ApiResponse<RequestPasswordResetOutput>, AuthError>

Source

pub async fn reset_password( &self, input: ResetPasswordInput, ) -> Result<ApiResponse<Status>, AuthError>

Trait Implementations§

Source§

impl<D> Debug for Api<'_, D>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, D> !RefUnwindSafe for Api<'a, D>

§

impl<'a, D> !UnwindSafe for Api<'a, D>

§

impl<'a, D> Forget for Api<'a, D>

§

impl<'a, D> Freeze for Api<'a, D>
where &'a Arc<Shared<D>>: Freeze, Option<(Arc<D>, DeferredEvents)>: Freeze,

§

impl<'a, D> Move for Api<'a, D>

§

impl<'a, D> Send for Api<'a, D>
where &'a Arc<Shared<D>>: Send, Option<(Arc<D>, DeferredEvents)>: Send,

§

impl<'a, D> Sync for Api<'a, D>
where &'a Arc<Shared<D>>: Sync, Option<(Arc<D>, DeferredEvents)>: Sync,

§

impl<'a, D> Unpin for Api<'a, D>
where &'a Arc<Shared<D>>: Unpin, Option<(Arc<D>, DeferredEvents)>: Unpin,

§

impl<'a, D> UnsafeUnpin for Api<'a, D>
where &'a Arc<Shared<D>>: UnsafeUnpin, Option<(Arc<D>, DeferredEvents)>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more