Trait bonsaidb_core::api::Api

source ·
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§

source

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.

source

type Error: ApiError

The error type that this can return.

Required Methods§

source

fn name() -> ApiName

Returns the unique name of this api.

Implementors§

source§

impl Api for AlterUserPermissionGroupMembership

§

type Error = Error

§

type Response = ()

source§

impl Api for AlterUserRoleMembership

§

type Error = Error

§

type Response = ()

source§

impl Api for ApplyTransaction

source§

impl Api for AssumeIdentity

source§

impl Api for Authenticate

source§

impl Api for Compact

§

type Error = Error

§

type Response = ()

source§

impl Api for CompactCollection

§

type Error = Error

§

type Response = ()

source§

impl Api for CompactKeyValueStore

§

type Error = Error

§

type Response = ()

source§

impl Api for Count

source§

impl Api for CreateDatabase

§

type Error = Error

§

type Response = ()

source§

impl Api for CreateSubscriber

source§

impl Api for CreateUser

source§

impl Api for DeleteDatabase

§

type Error = Error

§

type Response = ()

source§

impl Api for DeleteDocs

source§

impl Api for DeleteUser

§

type Error = Error

§

type Response = ()

source§

impl Api for ExecuteKeyOperation

source§

impl Api for Get

source§

impl Api for GetMultiple

source§

impl Api for LastTransactionId

source§

impl Api for List

source§

impl Api for ListAvailableSchemas

source§

impl Api for ListDatabases

source§

impl Api for ListExecutedTransactions

source§

impl Api for ListHeaders

source§

impl Api for LogOutSession

§

type Error = Error

§

type Response = ()

source§

impl Api for MessageReceived

source§

impl Api for Publish

§

type Error = Error

§

type Response = ()

source§

impl Api for PublishToAll

§

type Error = Error

§

type Response = ()

source§

impl Api for Query

source§

impl Api for QueryWithDocs

source§

impl Api for Reduce

§

type Error = Error

§

type Response = Bytes

source§

impl Api for ReduceGrouped

source§

impl Api for SetUserPassword

§

type Error = Error

§

type Response = ()

source§

impl Api for SubscribeTo

§

type Error = Error

§

type Response = ()

source§

impl Api for UnregisterSubscriber

§

type Error = Error

§

type Response = ()

source§

impl Api for UnsubscribeFrom

§

type Error = Error

§

type Response = ()