Create collection
In Appwrite, data is stored as a collection of documents. Create a collection in the Appwrite Console to store our ideas.
Create a new collection with the following attributes:
Field | Type | Required |
title | String | Yes |
content | String | Yes |
Connect database to the Refine app
Now that you have a collection to hold blog post contents, we can read and write to it from our app.
To integrate Appwrite API with the Refine App,
Add a resources array to the <Refine /> component in App.tsx
Include your Appwrite Database ID in both dataProvider and liveProvider, and specify the Appwrite Collection ID in the resource name property.
import { dataProvider, liveProvider } from '@refinedev/appwrite';
...
<Refine
dataProvider={dataProvider(appwriteClient, {
databaseId: "<APPWRITE_DATABASE_ID>",
})}
liveProvider={liveProvider(appwriteClient, {
databaseId: "<APPWRITE_DATABASE_ID>",
})}
authProvider={authProvider}
routerProvider={routerProvider}
resources={[
{
name: "<APPWRITE_COLLECTION_ID>", // resource name must be the same as APPWRITE_COLLECTION_ID.
list: "/posts", // Means that the list action of this resource will be available at /posts in your app
create: "/posts/create", // create action of this resource will be available at /posts/create
edit: "/posts/edit/:id", // edit action of this resource will be available at /posts/edit/:id
show: "/posts/show/:id", // show action of this resource will be available at /posts/show/:id
},
]}
...
/>;
Key concepts to performing CRUD operations:
A resource connects an API endpoint's entity with the app's pages, enabling them to interact with the API data. In the resource configuration, path definitions allow Refine to automatically recognize the resource's available actions and identify it based on the current path, eliminating the need for manual specification in hooks and components.
The data provider serves as your app's data layer, handling HTTP requests and managing data retrieval. Refine uses this through data hooks. With built-in support for Appwrite in Refine, you only need to pass your Appwrite database ID to the dataProvider property.
Note
The @refinedev/appwrite package supports Live/Realtime Provider natively.
At this point, we created our Appwrite database and connected to the Refine App.
You can now register and login to the app.