Trait bonsaidb::core::api::Api

pub trait Api: Serialize + for<'de> Deserialize<'de> + Send + Sync + Debug + 'static {
    type Response: Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync + Debug;
    type Error: ApiError;

    // Required method
    fn name() -> ApiName;
}
Expand description

An API request type. This trait is used by BonsaiDb’s server to allow a client to send a request of this type, and the server can respond with a Result<Api::Response,Api::Error>.

Deriving this trait

This trait can be derived. The only required attribute is name:

  • name = "api-name" or name = "api-name", authority = "api-authority": Configures the Api’s fully qualified name. This name must be unique across all other Apis installed. When creating an Api that is meant to be reused, ensure that a unique authority is used to prevent name collisions.
  • response = ResponseType: Configures the Api::Response associated type. This is the type that the handler will return upon success. If not specified, () is used.
  • error = ErrorType: Configures the Api::Error associated type. This is the type that the handler will return upon error. If not specified, Infallible is used.
use bonsaidb_core::api::Api;
use serde::{Deserialize, Serialize};

#[derive(Api, Debug, Serialize, Deserialize)]
#[api(name = "list-records", response = Vec<Record>)]
struct ListRecords {
    starting_id: u64,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
struct Record {
    title: String,
}

Required Associated Types§

type Response: Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync + Debug

The type that represents an API response. This type will be sent to clients from the server.

type Error: ApiError

The error type that this can return.

Required Methods§

fn name() -> ApiName

Returns the unique name of this api.

Implementors§

§

impl Api for AlterUserPermissionGroupMembership

§

type Error = Error

§

type Response = ()

§

impl Api for AlterUserRoleMembership

§

type Error = Error

§

type Response = ()

§

impl Api for ApplyTransaction

§

impl Api for AssumeIdentity

§

impl Api for Authenticate

§

impl Api for Compact

§

type Error = Error

§

type Response = ()

§

impl Api for CompactCollection

§

type Error = Error

§

type Response = ()

§

impl Api for CompactKeyValueStore

§

type Error = Error

§

type Response = ()

§

impl Api for Count

§

impl Api for CreateDatabase

§

type Error = Error

§

type Response = ()

§

impl Api for CreateSubscriber

§

impl Api for CreateUser

§

impl Api for DeleteDatabase

§

type Error = Error

§

type Response = ()

§

impl Api for DeleteDocs

§

impl Api for DeleteUser

§

type Error = Error

§

type Response = ()

§

impl Api for ExecuteKeyOperation

§

impl Api for Get

§

impl Api for GetMultiple

§

impl Api for LastTransactionId

§

impl Api for List

§

impl Api for ListAvailableSchemas

§

impl Api for ListDatabases

§

impl Api for ListExecutedTransactions

§

impl Api for ListHeaders

§

impl Api for LogOutSession

§

type Error = Error

§

type Response = ()

§

impl Api for MessageReceived

§

impl Api for Publish

§

type Error = Error

§

type Response = ()

§

impl Api for PublishToAll

§

type Error = Error

§

type Response = ()

§

impl Api for Query

§

impl Api for QueryWithDocs

§

impl Api for Reduce

§

impl Api for ReduceGrouped

§

impl Api for SetUserPassword

§

type Error = Error

§

type Response = ()

§

impl Api for SubscribeTo

§

type Error = Error

§

type Response = ()

§

impl Api for UnregisterSubscriber

§

type Error = Error

§

type Response = ()

§

impl Api for UnsubscribeFrom

§

type Error = Error

§

type Response = ()