<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Irshit Mukherjee</title>
    <description>The latest articles on DEV Community by Irshit Mukherjee (@irshit033).</description>
    <link>https://dev.to/irshit033</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F859511%2F9e301c32-e8b5-4055-b4bf-cb9ece5b4a3d.png</url>
      <title>DEV Community: Irshit Mukherjee</title>
      <link>https://dev.to/irshit033</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/irshit033"/>
    <language>en</language>
    <item>
      <title>Getting Started with Appwrite (Web)+Realtime data updating in Appwrite</title>
      <dc:creator>Irshit Mukherjee</dc:creator>
      <pubDate>Mon, 16 May 2022 08:58:19 +0000</pubDate>
      <link>https://dev.to/irshit033/getting-started-with-appwrite-webrealtime-data-updating-in-appwrite-1jeb</link>
      <guid>https://dev.to/irshit033/getting-started-with-appwrite-webrealtime-data-updating-in-appwrite-1jeb</guid>
      <description>&lt;h2&gt;
  
  
  What is Appwrite?
&lt;/h2&gt;

&lt;p&gt;Managing your frontend and backend all alone in short span of time is really hard. Here comes Backend as a Service to this picture. We all heard of Firebase. Appwrite is a Firebase(Backend as a Service) Alternative which is opensource.It provides developers with  all the necessary APIs thats required to build any application.We can use this tool in any platform like Web ,mobile.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;We have to install it using Docker.&lt;br&gt;
  now copy-paste this to your terminal.&lt;/p&gt;
&lt;h3&gt;
  
  
  In Unix
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -it --rm \
    --volume /var/run/docker.sock:/var/run/docker.sock \
    --volume "$(pwd)"/appwrite:/usr/src/code/appwrite:rw \
    --entrypoint="install" \
    appwrite/appwrite:0.13.4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  In CMD
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -it --rm ^
    --volume //var/run/docker.sock:/var/run/docker.sock ^
    --volume "%cd%"/appwrite:/usr/src/code/appwrite:rw ^
    --entrypoint="install" ^
    appwrite/appwrite:0.13.4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  In PowerShell
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -it --rm ,
    --volume /var/run/docker.sock:/var/run/docker.sock ,
    --volume ${pwd}/appwrite:/usr/src/code/appwrite:rw ,
    --entrypoint="install" ,
    appwrite/appwrite:0.13.4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;and now run the Appwrite user Dashboard in localhost:80&lt;br&gt;
then create your project.&lt;/p&gt;

&lt;p&gt;then you have to install appwrite sdk in your project&lt;br&gt;
&lt;code&gt;npm install appwrite&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;now its time to set up your package&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Appwrite } from "appwrite";
export const appwrite = new Appwrite();

appwrite.setEndpoint("&amp;lt;your_project_emdpoint&amp;gt;").setProject("&amp;lt;your_project_id&amp;gt;");
export const db=appwrite.database;
export const account = appwrite.account;
export const CollectionID="&amp;lt;your_data_base_collection_id&amp;gt;";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make your First request&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;appwrite.account.create('unique()', 'me@example.com', 'password', 'Jane Doe')
        .then(response =&amp;gt; {
            console.log(response);
        }, error =&amp;gt; {
            console.log(error);
        });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congrats! you  have successfully made your first request (Registering a User)&lt;br&gt;
now your go through the documents of appwrite web sdk&lt;br&gt;
 &lt;a href="https://appwrite.io/docs/getting-started-for-web"&gt;documentation appwrite&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  RealTime with appwrite
&lt;/h3&gt;

&lt;p&gt;for executing Realtime you have to subscribe a channel&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sdk = new Appwrite();

sdk.subscribe(['collections.name_of_your_collection.documents'], response =&amp;gt; {
    // Callback will be executed on changes for documents A and all files.
    console.log(response);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;first parameter of subscribe function contains array of channels that can be 'collections.name_of_your_collection.documents' or 'files' or 'account' .According to your channel you can perform realtime updates in specific functionality.&lt;/p&gt;

&lt;p&gt;After this you have to unsubscribe when you don't want to receive updates from a subscription&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sdk = new Appwrite();

const unsubscribe = sdk.subscribe('files', response =&amp;gt; {
    // Callback will be executed on changes for all files.
    console.log(response);
});

// Closes the subscription.
unsubscribe();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Code Example in React
&lt;/h3&gt;

&lt;p&gt;in your useEffect hook you can write your subscribe/unsubscribe code like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect(() =&amp;gt; {
    const unsubscribe= 
appwrite.subscribe(['collection.&amp;lt;put_your_collection_name&amp;gt;.documents'],(data)=&amp;gt;{
      if(data.event==='database.documents.update'){
        setmsg((msgs)=&amp;gt;[...msgs,data.payload]);
      }
    });

 return ()=&amp;gt;{
    unsubscribe();
  }

  }, [])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also you can check out my git repo where i build a webapp.this web-app lands with a login/ signup page(user can switch between two according to their convenience). After the user has logged in, the dashboard of the user comes up where it shows the username, email and number of contributions of the respective user. It has been implemented using Appwrite SDK. We then have our most interesting part of the web-app which is the 'Contribtion' section where user can answer to the problems asked by an author in real-time. User can also be an author and post their respective doubts or the problem they are facing in the code(user are also allowed to attach their code screenshots).&lt;/p&gt;

&lt;p&gt;github repo link :-&lt;a href="https://github.com/IRSHIT033/Appwrite"&gt;linkgithubrepo&lt;/a&gt; &lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>appwrite</category>
    </item>
  </channel>
</rss>
