<?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: 17th_streetCode</title>
    <description>The latest articles on DEV Community by 17th_streetCode (@ikehakinyemi).</description>
    <link>https://dev.to/ikehakinyemi</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%2F276115%2Ffcd0dbe4-9d0c-44d0-aaa9-194cf158f061.jpg</url>
      <title>DEV Community: 17th_streetCode</title>
      <link>https://dev.to/ikehakinyemi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ikehakinyemi"/>
    <language>en</language>
    <item>
      <title>How to implement Fauna add-on for Netlify applications
</title>
      <dc:creator>17th_streetCode</dc:creator>
      <pubDate>Tue, 30 Nov 2021 15:37:47 +0000</pubDate>
      <link>https://dev.to/ikehakinyemi/how-to-implement-fauna-add-on-for-netlify-applications-3p2l</link>
      <guid>https://dev.to/ikehakinyemi/how-to-implement-fauna-add-on-for-netlify-applications-3p2l</guid>
      <description>&lt;p&gt;In this tutorial, you learn about the following topics&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Introduction to Fauna and Fauna Add-on For Netlify&lt;/li&gt;
&lt;li&gt;Introduction to FaaS with Fauna and Netlify.&lt;/li&gt;
&lt;li&gt;Build a Notes application with Netlify functions ( Clone the application from GitHub).&lt;/li&gt;
&lt;li&gt;Explain the code and processes involved in setting up Fauna Add-on for the Netlify application built in this tutorial.&lt;/li&gt;
&lt;li&gt;Test our application.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Feel free to navigate through the different sections of the article using the content list provided. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Fauna add-on for Netlify
&lt;/h1&gt;

&lt;p&gt;Serverless computing are services that offer developers an increasingly higher levels of abstraction in the form of serverless offerings. These services are exposed to the developers as APIs that are consumed in applications to reduce or remove the hassle of handling the operational complexity within these applications.  Fauna provides a flexible, developer-friendly, transactional database delivered as a serverless, secure and scalable cloud APIs. This means that our database is provided as a “client-serverless” application through serverless APIs. These “&lt;a href="https://fauna.com/client-serverless?utm_source=DevTo&amp;amp;utm_medium=referral&amp;amp;utm_campaign=WritewithFauna_FaunaAddonNetlify_IAkinyemi"&gt;client-serverless&lt;/a&gt;” applications are written as rich, browser-native clients.&lt;/p&gt;

&lt;p&gt;Fauna Add-on Netlify as an integration makes it easy to use Fauna as the apt database for your Netlify sites and functions.  Netlify is a serverless computing company that offers hosting services, and serverless backend services for web applications and static websites. Now with Fauna Add-on Netlify, we can configure and implement a Netlify-specific database, and whilst creating this database, an access token is created and stored in a secured environment variable. Through this means the Fauna Add-on Netlify tool provides us with the basic resources needed to start building Netlify serverless functions that connects to the FaunaDB solely.&lt;/p&gt;

&lt;h1&gt;
  
  
  Introduction to FaaS with Fauna and Netlify
&lt;/h1&gt;

&lt;p&gt;The term &lt;strong&gt;FaaS,&lt;/strong&gt; also know as “Functions as a Service”, is a category of the clouding computing that allows developers to develop, run and manage application functionalities (microservices) without the hassle of maintaining this infrastructure. The underlying concept is the event-driven computing paradigm wherein application code, or containers, only run in response to events or requests. This means your application executes serverless code in response to events happening within your application. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://dashboard.fauna.com/accounts/register?utm_source=DevTo&amp;amp;utm_medium=referral&amp;amp;utm_campaign=WritewithFauna_FaunaAddonNetlify_IAkinyemi"&gt;Fauna&lt;/a&gt; is a serverless cloud database that offers fast and reliable global access to database via modern APIs, like GraphQL, without sacrificing data consistency. Fauna database can be accessed via HTTPS and there is no cross-database data contamination. Netlify as a serverless platform hosts our serverless applications that communicates with these databases.&lt;/p&gt;

&lt;h1&gt;
  
  
  Build a notes application with Netlify functions
&lt;/h1&gt;

&lt;p&gt;Now let’s set up the Notes application using &lt;code&gt;npm&lt;/code&gt;  and &lt;code&gt;netlify-cli&lt;/code&gt;, and as well configure some default settings on the project. With Netlify CLI, we can set up continuous deployment for our project through the terminal, even run development server or deploy our project.&lt;/p&gt;

&lt;p&gt;Before we continue any further, let’s clone the below repository on GitHub into a &lt;strong&gt;Add-on-netlify&lt;/strong&gt; folder. This folder would be automatically created while running the &lt;code&gt;git clone&lt;/code&gt;  command. Then we’ll setup CI/CD on this folder using the Netlify CLI tool.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/IkehAkinyemi/fauna-add-on-netlify Add-on-netlify
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now we’ve created a folder named &lt;strong&gt;Add-on-netlify&lt;/strong&gt;, let’s change directory into it:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd Add-on-netlify
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And inside it we’ll install dependencies that would be used in building our project:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i netlify-cli -g
npm install faunadb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This above command would install the Netlify CLI globally on our local system, and installs JavaScript Driver for FaunaDB. We’ll use the JavaScript Driver to make HTTPS requests to our database to perform the CRUD operations on it. Netlify CLI would help us setup our Netlify application without using the Netlify UI. All the configuring and hosting would be done through the terminal.&lt;/p&gt;

&lt;h1&gt;
  
  
  Setting up Fauna add-on for the Netlify application
&lt;/h1&gt;

&lt;p&gt;Let’s setup and configure Netlify for our project by running the below commands, while providing the right response to the questions needed by &lt;code&gt;netlify-cli&lt;/code&gt; to configure our project:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;netlify init

What would you like to do? Create &amp;amp; configure a new site
? Team: Ikeh_Chukwuka_Favour's team
Choose a unique site name (e.g. the-great-IkehAkinyemi-site.netlify.app) or leave it blank for a random name. You can update the site name later.
? Site name (optional): faunadb-add-on-netlify

Site Created

Site ID:   3d3b27bd-3f93-4968-acae-81ff45c69980
? Your build command (hugo build/yarn run build/etc): yarn run build
? Directory to deploy (blank for current dir): dist
? Netlify functions folder: netlify
Adding deploy key to repository...
Deploy key added!

Creating Netlify GitHub Notification Hooks...
Netlify Notification Hooks configured!

Success! Netlify CI/CD Configured!

This site is now configured to automatically deploy from github branches &amp;amp; pull requests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;With the above success message, we have successfully linked this project to the Netlify. And at the same time setup CI/CD on the repository, &lt;code&gt;https://github.com/IkehAkinyemi/fauna-add-on-netlify&lt;/code&gt;. This means that any update we push to this repository reflects on the deployed application on Netlify.&lt;/p&gt;

&lt;p&gt;Next, let create and add “fauna” to our deployed application as a &lt;strong&gt;add-on.&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;netlify addons:create fauna
# Add-on "fauna" created for faunadb-add-on-netlify
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now let’s authenticate the &lt;strong&gt;Add-on&lt;/strong&gt;, this way we’re actually setting up the database using the Fauna website that the command will open on our browser.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;netlify addons:auth fauna
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The above command would either open a sign up page on the Fauna website, or login page if you already have an account or the page to rename the default name given to your database if already logged in. Here, we’ll use the default name, &lt;code&gt;3d3b27bd-3f93-4968-acae-81ff45c69980&lt;/code&gt;, and import it into our account. After this, we now have full access to interact with this database.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ancZDRB1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_40E22FE96039A16D7268BEF3E4A8E299B7CB173E37E9E3233AEF04BCDCA5C1A8_1632440979136_faunadb-shitpay.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ancZDRB1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_40E22FE96039A16D7268BEF3E4A8E299B7CB173E37E9E3233AEF04BCDCA5C1A8_1632440979136_faunadb-shitpay.png" alt="alt-text" width="880" height="456"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once imported, click on the database and navigate to the &lt;strong&gt;Security&lt;/strong&gt; page through the sidebar to see the set of keys automatically generated for us. These keys are hidden and not accessible to anyone. The keys are stored in a private environment variables and the Netlify UI never displays them. &lt;/p&gt;

&lt;h1&gt;
  
  
  Configuring Fauna
&lt;/h1&gt;

&lt;p&gt;We going to test our application to make sure everything is properly working. Before we continue, let’s navigate to the Collection page and &lt;a href="https://dashboard.fauna.com/accounts/register?utm_source=DevTo&amp;amp;utm_medium=referral&amp;amp;utm_campaign=WritewithFauna_FaunaAddonNetlify_IAkinyemi"&gt;create a Collection&lt;/a&gt; named &lt;strong&gt;notes.&lt;/strong&gt; Click on the &lt;strong&gt;NEW COLLECTION&lt;/strong&gt; button to create a collection as below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u7LK6jWU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_40E22FE96039A16D7268BEF3E4A8E299B7CB173E37E9E3233AEF04BCDCA5C1A8_1632441245483_faunadb-shitpay-2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u7LK6jWU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_40E22FE96039A16D7268BEF3E4A8E299B7CB173E37E9E3233AEF04BCDCA5C1A8_1632441245483_faunadb-shitpay-2.png" alt="alt-text" width="880" height="455"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After we have successfully created our new collection, we can now go back to our project and run a local development server using the &lt;code&gt;netlify-cli&lt;/code&gt; tool.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;netlify dev
◈ Netlify Dev ◈
◈ Injected addon env var: FAUNADB_ADMIN_SECRET
◈ Injected addon env var: FAUNADB_SERVER_SECRET
◈ Injected addon env var: FAUNADB_CLIENT_SECRET
◈ Ignored general context env var: LANG (defined in process)
◈ Ignored general context env var: LANGUAGE (defined in process)
◈ No app server detected. Using simple static server
◈ Running static server from "Notes backend/dist"
◈ Loaded function create.
◈ Loaded function delete.
◈ Loaded function jokes.
◈ Loaded function read.
◈ Loaded function update.
◈ Functions server is listening on 36151

◈ Static server listening to 34503

   ┌──────────────────────────────────────────────────┐
   │                                                  │
   │   ◈ Server now ready on http://localhost:42375   │
   │                                                  │
   └──────────────────────────────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;From the above output, we can see that the &lt;code&gt;FAUNADB_ADMIN_SECRET&lt;/code&gt;,  &lt;code&gt;FAUNADB_SERVER_SECRET&lt;/code&gt; and the &lt;code&gt;FAUNADB_CLIENT_SECRET&lt;/code&gt; as &lt;strong&gt;Injected addon env var.&lt;/strong&gt; This means that Netlify is managing and providing us with this environment variables from a hidden source within our application. This provides security against hacks or security breaches within our applications. Also, from the output above, we have four serverless CRUD operations defined within our project. These serverless functions can be found in the &lt;code&gt;/serverless&lt;/code&gt; directory.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing our Application
&lt;/h2&gt;

&lt;p&gt;Now let open the url, &lt;code&gt;http://localhost:42375/&lt;/code&gt; in the browser. This is the local development port where the frontend of our project is hosted at:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QGokumIj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_40E22FE96039A16D7268BEF3E4A8E299B7CB173E37E9E3233AEF04BCDCA5C1A8_1632442563955_fauna-shitpay.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QGokumIj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_40E22FE96039A16D7268BEF3E4A8E299B7CB173E37E9E3233AEF04BCDCA5C1A8_1632442563955_fauna-shitpay.png" alt="alt-text" width="880" height="161"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Next let’s click on the &lt;code&gt;Create Note&lt;/code&gt; button which makes a &lt;code&gt;fetch&lt;/code&gt; request to the serverless function, &lt;code&gt;create&lt;/code&gt;, to create a Document on the database. Navigate back to the Fauna database page to confirm this action as below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3457V_N6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_40E22FE96039A16D7268BEF3E4A8E299B7CB173E37E9E3233AEF04BCDCA5C1A8_1632442895526_faunadb-shitpay-4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3457V_N6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_40E22FE96039A16D7268BEF3E4A8E299B7CB173E37E9E3233AEF04BCDCA5C1A8_1632442895526_faunadb-shitpay-4.png" alt="alt-text" width="880" height="331"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The data provided to this &lt;code&gt;fetch&lt;/code&gt; request to create the &lt;strong&gt;Document&lt;/strong&gt; can be found within the &lt;code&gt;/dist/js/main.js&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;Next action is to create a new &lt;code&gt;index&lt;/code&gt;. Navigate to the &lt;em&gt;Indexes&lt;/em&gt; page to create an index. Searching documents in Fauna can be done by using &lt;code&gt;indexes&lt;/code&gt;, specifically by matching inputs against an index’s &lt;code&gt;terms&lt;/code&gt; field. Click on the &lt;code&gt;NEW INDEX&lt;/code&gt; button to create an index. Once in create index screen, fill out the form: selecting the collection we’ve created previously, then giving a name to our index. In this tutorial, we will name ours &lt;strong&gt;all_notes&lt;/strong&gt;. We can now save our index.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5vIRDT70--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_40E22FE96039A16D7268BEF3E4A8E299B7CB173E37E9E3233AEF04BCDCA5C1A8_1632443798369_faunadb-shitpay-5.0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5vIRDT70--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_40E22FE96039A16D7268BEF3E4A8E299B7CB173E37E9E3233AEF04BCDCA5C1A8_1632443798369_faunadb-shitpay-5.0.png" alt="alt-text" width="880" height="456"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, click on the &lt;code&gt;Read All Notes&lt;/code&gt; button to get the &lt;strong&gt;Documents&lt;/strong&gt; created on the database. Check the terminal for the response as we used the &lt;code&gt;console.log&lt;/code&gt; function to output the response there.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Request from ::1: GET /.netlify/functions/read
[
  {
    ref: Ref(Collection("notes"), "123"),
    ts: 1632442835420000,
    data: { name: 'Todo-list', desc: "Patrick's mother" }
  }
]
Response with status 200 in 864 ms.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next, we insert a new document. You can find this document in &lt;a href="https://github.com/IkehAkinyemi/fauna-add-on-netlify/blob/main/dist/js/main.js#L26"&gt;github&lt;/a&gt; repo. Let’s click on the &lt;code&gt;Update Note&lt;/code&gt; button and navigate back to the Fauna database page to confirm this action as below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4qfcJCto--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_40E22FE96039A16D7268BEF3E4A8E299B7CB173E37E9E3233AEF04BCDCA5C1A8_1632445134636_fuanadb-shitpay-6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4qfcJCto--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_40E22FE96039A16D7268BEF3E4A8E299B7CB173E37E9E3233AEF04BCDCA5C1A8_1632445134636_fuanadb-shitpay-6.png" alt="alt-text" width="880" height="455"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let’s perform the last CRUD action which is the &lt;code&gt;delete&lt;/code&gt; action on our database. Click on the &lt;code&gt;Delete Note&lt;/code&gt; button and navigate back to the Fauna database page to confirm this action as below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qNzBMvpw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_40E22FE96039A16D7268BEF3E4A8E299B7CB173E37E9E3233AEF04BCDCA5C1A8_1632445304492_faunadb-shitpay-7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qNzBMvpw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_40E22FE96039A16D7268BEF3E4A8E299B7CB173E37E9E3233AEF04BCDCA5C1A8_1632445304492_faunadb-shitpay-7.png" alt="alt-text" width="880" height="456"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we don’t have &lt;strong&gt;Document&lt;/strong&gt; in our collection as the &lt;code&gt;deleteOne&lt;/code&gt; function had made a &lt;code&gt;fetch&lt;/code&gt; request to the serverless action, &lt;code&gt;delete&lt;/code&gt;, on our database.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;I’m glad you followed the tutorial to this point, hope you’ve learned how to use &lt;a href="https://docs.fauna.com/fauna/current/integrations/netlify"&gt;Fauna Add-on Netlify&lt;/a&gt; tool to integrate &lt;a href="https://docs.fauna.com/fauna/current/"&gt;Fauna&lt;/a&gt; into a Netlify site or functions. The combination of Fauna with Netlify concepts provides you the capacity to build great web application, from e-commerce application to Notes keeping application, or any web application without exposing your secret keys which would be stored and retrieved through the Add-on tool on the application. Here’s the &lt;a href="https://github.com/IkehAkinyemi/fauna-add-on-netlify"&gt;GitHub link&lt;/a&gt; to code sample we used within our tutorial.&lt;/p&gt;

</description>
      <category>fauna</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>database</category>
    </item>
    <item>
      <title>Intro to Doppler: Building Express Application With Doppler And FaunaDB</title>
      <dc:creator>17th_streetCode</dc:creator>
      <pubDate>Tue, 28 Sep 2021 02:16:43 +0000</pubDate>
      <link>https://dev.to/ikehakinyemi/intro-to-doppler-building-express-application-with-doppler-and-faunadb-5e1n</link>
      <guid>https://dev.to/ikehakinyemi/intro-to-doppler-building-express-application-with-doppler-and-faunadb-5e1n</guid>
      <description>&lt;p&gt;Building full-stack Express applications would always involve connecting to a database or external resources that are needed to have functional applications. When connecting to these external resources we would need a means of verifying our identity before making a successful connection. We use special secret keys or API keys that are peculiar to our application to verify our identity. These keys should always be kept secret from the public eye as the Web is an open village or we stand to lose our application to cybersecurity attacks. Managing secret API keys on the backend application has been strenuous and many solutions like using the .env file have been proposed, but these solutions have not been any efficient when deployed to the Web.&lt;/p&gt;

&lt;h1&gt;
  
  
  Introduction to Doppler Secret Management
&lt;/h1&gt;

&lt;p&gt;Doppler has since its invention made secret management easier by reducing the complexity involved in securing the secret resources needed within our application for it to work. Doppler as a tool integrated into our application helps our application scale as it increases in functionalities providing it with fine-grained access controls, logs, versioning.&lt;/p&gt;

&lt;p&gt;Doppler provides a secure and scalable Universal Secrets Manager that makes development for developers easier by removing any need for .env files, or the unnecessary hardcoded secrets and copy-pasted credentials. This Universal Secrets Manager works for almost all the programming languages regardless of their steadily growing list of integrations. Doppler can be integrated into an existing project or your first project by following the self-explanatory docs for installing Doppler. The Doppler CLI tool makes it a whole lot easier to access the secrets in any environment, either the development environment or production. Also, we’re provided with a dashboard to manage our application configurations.&lt;/p&gt;

&lt;p&gt;To avoid breaking code in production, Doppler automatically creates a snapshot of our latest secrets and stores it in an encrypted file. During development, if we couldn’t get access to the API that we connect to with the secret keys, the Doppler CLI smartly fallsback to the snapshot from the encrypted file.&lt;/p&gt;

&lt;p&gt;Next, let’s start building and implementing the different parts of our backend application. This will involve a series of simple steps to define and then start our server. Let’s create a folder named Doppler project, change directory into this folder, and then at the root of the folder initialize an Express application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir “Doppler project”
cd Doppler\ project/
npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s install the dependencies needed within our application to implement some functionalities:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install express faunadb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above command would install the Express library, and the JavaScript Driver, faunadb, for connecting to the database. Click here to set up a Fauna account if you don’t have anyone.&lt;br&gt;
In the dashboard, click on the “NEW DATABASE” button, provide a name for your database then press the SAVE button.&lt;br&gt;
Once you’ve created your database, you’ll need to create a collection named Posts. This is what we’ll be interacting with within our source code to create a Document (a post) within our application.&lt;br&gt;
Now let create our /server.js file, and update it with the following code to implement a server for our application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require(“express”);
const faunadb = require(“faunadb”),
const q = faunadb.query;
const secret = process.env.FAUNADB_SERVER_SECRET;
const client = new faunadb.Client({
secret: secret,
});
const app = express();
app.use(express.json());
const PORT = process.env.PORT || 8000;
app.listen(PORT, () =&amp;gt; console.log(`🚀🚀 Server listening at port ${PORT} 🚀🚀🚀`));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let’s define the different routes that would connect our backend application to the database and perform CRUD actions on it when we send requests to the server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
app.post('/posts', async (req, res) =&amp;gt; {
try {
const {post, description } = req.body;
const { data } = await client.query(
q.Create(q.Collection('Posts'), { data: { post, description } })
);
res.status(201).json(data);
} catch (error) {
res.status(500).json({error: error.description})
}
});
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code, we’re creating a post data (Document) in our database when we make a POST request on the /posts path of our application.&lt;br&gt;
To test our application routes, we’ll use any HTTPS client, and for this tutorial, we’ll be using the Postman application to test it.&lt;br&gt;
Before we start testing our application, let’s implement another route, to get all the Documents (posts) within our application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
app.get('/posts', async (req, res) =&amp;gt; {
try {
let { data } = await client.query(
q.Map(
q.Paginate(q.Documents(q.Collection("Posts"))),
q.Lambda("X", q.Get(q.Var("X")))
)
)
res.status(200).json(data[0][“data”])
} catch (error) {
res.status(500).json({error: error.description})
}
});
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we’ve implemented the routes for our application, let’s set up Doppler for our project to manage our environment variables, aka secret keys.&lt;br&gt;
Let’s create a Doppler account by clicking here. Follow the user-friendly steps to create an account, and once created, go ahead to create a workspace with any name you want.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GVlxc4yA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5493lrtfex0fdi9klzpc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GVlxc4yA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5493lrtfex0fdi9klzpc.png" alt="AltText"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After creating a workspace, follow the Doppler friendly walkthrough to understand some of the functionalities and features of Doppler.&lt;br&gt;
Next, let’s create a new project on Doppler. Click on the Project link, then click on the plus icon to create and add a new project to the workspace. We’ll name it Doppler-Express. Once created, we’re provided with three environments for our project namely:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Development&lt;/li&gt;
&lt;li&gt;Staging&lt;/li&gt;
&lt;li&gt;Production&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are environments for managing the secret resources we’ll use within our application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FzIVxmPn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ix7a0cp93s2gcl8809z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FzIVxmPn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ix7a0cp93s2gcl8809z.png" alt="AltText"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we have our project set up on the Doppler website, let setup our local environment on our local machine using the Doppler CLI.&lt;/p&gt;
&lt;h1&gt;
  
  
  Set Up Doppler On The Local Environment Using The Doppler CLI
&lt;/h1&gt;

&lt;p&gt;Let’s proceed ahead to install the Doppler CLI which will help us in the development stage of our application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Install pre-reqs
sudo apt-get update &amp;amp;&amp;amp; sudo apt-get install -y apt-transport-https ca-certificates curl gnupg
# Add Doppler's GPG key
curl -sLf --retry 3 --tlsv1.2 --proto "=https" 'https://packages.doppler.com/public/cli/gpg.DE2A7741A397C129.key' | sudo apt-key add -
# Add Doppler's apt repo
echo "deb https://packages.doppler.com/public/cli/deb/debian any-version main" | sudo tee /etc/apt/sources.list.d/doppler-cli.list
# Fetch and install latest doppler cli
sudo apt-get update &amp;amp;&amp;amp; sudo apt-get install doppler
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we’ve finished configuring and installing Doppler CLI on our local machine, run the following code to confirm that it was installed successfully.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;doppler  --version
# v3.32.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, let’s authenticate our local development with the remote development environment as they would need to be in sync with each other.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;doppler login
? Open the authorization page in your browser? Yes
Your auth code is:
XXXXh_XXXXphone_bus_XXXXo_XXXXville
Waiting...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This opens the browser to log into your account and authenticate your local environment. Fill in your email or login with Google, then copy and paste the auth token that’s displayed on the terminal, to authenticate Doppler.&lt;br&gt;
Inside the root, run the doppler setup command and select the right option to configure your local environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;doppler setup
? Select a project: doppler-express
? Select a config: dev
┌─────────┬─────────────────┬─────────────────────────────────────────────────┐
│ NAME    │ VALUE           │ SCOPE                                           │
├─────────┼─────────────────┼─────────────────────────────────────────────────┤
│ config  │ dev             │ /home/ikehakinyemi/Projects/NodeJS/Doppler proj │
│         │                 │ ect                                             │
│ project │ doppler-express │ /home/ikehakinyemi/Projects/NodeJS/Doppler proj │
│         │                 │ ect                                             │
└─────────┴─────────────────┴─────────────────────────────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let’s return back to our remote project on the website and click on the dev section of the project. Then click on the Add Secret to add a new secret as below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GKq5MEje--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pxuvwsl3zjmabz2fkrac.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GKq5MEje--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pxuvwsl3zjmabz2fkrac.png" alt="AltText"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add the name of your secret key and paste in the value of the secret key, which is the secret key itself. Click on the Save button to add the secret key to the dev environment.&lt;br&gt;
Return back to your terminal and run the following command to confirm that your secret key is in sync with your remote environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo $(doppler secrets get FAUNADB_SERVER_SECRET --plain)
fnAEUIdhSoACXXXXXXXX-n6QxpBZXXXXXXXXpkBp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let’s use Postman to test our application and make sure our routes are accessing the database:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--04aQYkD6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/owaikxssma8igkrteoi1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--04aQYkD6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/owaikxssma8igkrteoi1.png" alt="AltText"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first Document has been successfully been created on the database. Log into your database and confirm it.&lt;br&gt;
Next, let’s check the second route which is a GET request, to return all the Documents from the database as below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--asgAtN2H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7htjrgff7isy9rm4rc2z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--asgAtN2H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7htjrgff7isy9rm4rc2z.png" alt="AltText"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;We’ve successfully set up Doppler for an Express application to securely hide and manage our secret keys used for its development. We eliminated the need to have a .env file, and can now easily manage these secret keys among our friends or team by giving them access to the Workspace on the Doppler website. And we can integrate Doppler services in any Node.JS application as it uses the native approach of retrieving the environment variables through the process.env[“YOUR_SECRET_KEY”]. The code used in this tutorial can be found on &lt;a href="https://github.com/IkehAkinyemi/Doppler-Express"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How To Use Fauna And Serverless Framework To Build Serverless Application.</title>
      <dc:creator>17th_streetCode</dc:creator>
      <pubDate>Tue, 13 Jul 2021 01:55:48 +0000</pubDate>
      <link>https://dev.to/ikehakinyemi/how-to-use-fauna-and-serverless-framework-to-build-serverless-application-b7p</link>
      <guid>https://dev.to/ikehakinyemi/how-to-use-fauna-and-serverless-framework-to-build-serverless-application-b7p</guid>
      <description>&lt;p&gt;Written in connection with the &lt;a href="https://www2.fauna.com/write-with-fauna"&gt;Write With Fauna program&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Quick summary—We’ll explore the different parts/tools needed to build a serverless application with Fauna and serverless framework. We’ll cover the different working parts of an application that makes it serverless. &lt;/p&gt;

&lt;p&gt;To begin, we’ll start with the underlying concept of serverless, serverless applications, and what makes them different from our regular applications. We will cover the roles Fauna and serverless framework play within serverless applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;When developers unfamiliar with serverless hear the term, their first thought is that it doesn't require servers. However, your application still requires servers to function. A simple explanation to serverless is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Serverless computing is a method of providing backend services on an as-used basis. The servers are still used, but the developer(s) or the company that gets backend services from a serverless vendor is charged based on his/her or their computation—usage, not as a fixed amount of bandwidth or number of servers.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This allows the serverless provider to provide the services needed by the users to write and deploy code without the hassle of worrying about the underlying infrastructure needed for the application.&lt;/p&gt;

&lt;p&gt;Within this tutorial, we’ll discuss serverless as &lt;strong&gt;function-as-a-service&lt;/strong&gt;, a serverless backend service allowing developers to write and update modular pieces of code on the fly. These pieces of code are executed in response to certain events within the application. The approach would be to write our code in the form of functions that would handle different tasks or requests within the application. So when we deploy our functions, we’ll invoke them in the format of an event.&lt;/p&gt;

&lt;p&gt;This &lt;strong&gt;function-as-a-service&lt;/strong&gt; gives serverless applications the ability to scale dynamically per request, and won’t require any capacity planning or provisioning for the application.&lt;/p&gt;

&lt;p&gt;That brings us to a common issue that we face when building serverless applications. Available popular cloud databases are yet to have this support level of elasticity—you have to pay for capacity you don’t use. Then there’s also the lack of operations like joins, indexes, authentication, and other capabilities necessary to build a rich application. This brings Fauna into the picture.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction To Fauna And Serverless Framework
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://fauna.com/"&gt;&lt;strong&gt;Fauna&lt;/strong&gt;&lt;/a&gt; uses a pre-existing infrastructure to build web applications without the usual setting-up of custom settings. Our applications' capacity is metered and available on-demand—we'll only pay for what we use within our serverless application. &lt;a href="https://fauna.com/"&gt;Fauna&lt;/a&gt; is a flexible, developer-friendly, transactional database delivered as a secure and scalable cloud API with native GraphQL. This gives the flexibility that provides us with reasons never to worry about database provisioning, scaling, sharing, replication, or correctness.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Serverless Framework&lt;/strong&gt; is an open source software that builds, compiles, and packages code for &lt;strong&gt;serverless&lt;/strong&gt; deployment and then deploys the package to the cloud. &lt;a href="https://www.serverless.com/framework/docs/"&gt;Serverless Framework&lt;/a&gt; helps develop, deploy, troubleshoot and secure our serverless applications with radically less overhead and cost by using the Serverless Framework. The Serverless Framework consists of an open-source CLI and a hosted dashboard. Together, they provide you with full serverless application lifecycle management.&lt;/p&gt;

&lt;p&gt;Let’s dive into exploring the different parts of serverless application with Fauna and Serverless Framework.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisite
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Basic knowledge of Fauna, yet not compulsory&lt;/li&gt;
&lt;li&gt;Have NodeJS v12.0 or a higher version installed on our local machine.&lt;/li&gt;
&lt;li&gt;Basic knowledge of Serverless Framework, yet not compulsory&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Get started with Serverless Framework
&lt;/h2&gt;

&lt;p&gt;Our first approach would be the installation of &lt;a href="https://www.serverless.com/framework/docs/getting-started/"&gt;Serverless framework&lt;/a&gt; globally on our local machine to quickly set up and provision serverless functions on multiple cloud providers.&lt;/p&gt;

&lt;p&gt;We can install Serverless framework as a standalone binary or with npm. We’ll cover both installations for preference’s sake.&lt;/p&gt;

&lt;p&gt;Install as a standalone binary:&lt;/p&gt;

&lt;h3&gt;
  
  
  MacOS/Linux
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -o- -L https://slss.io/install | bash 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above command will install the latest version, just run the command in your terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -o- -L https://slss.io/install | VERSION=2.21.1 bash 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Window
&lt;/h3&gt;

&lt;p&gt;We’ll use one of the Windows’ package manager, &lt;a href="https://chocolatey.org/"&gt;Chocolatey&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;choco install serverless 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install through &lt;strong&gt;npm&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g serverless 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above command installs the serverless CLI through the node package manager, npm.&lt;/p&gt;

&lt;p&gt;Once the installation is through, it will look for AWS keys in the normal environment variables.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get started with Fauna
&lt;/h2&gt;

&lt;p&gt;We’ll start by signing in into our existing Fauna account to get started with Fauna, or register for a new account as a new user using either email credentials or using an existing Github account. Register for a new account &lt;a href="https://dashboard.fauna.com/accounts/register"&gt;here&lt;/a&gt;. Once the account is created or signed in, you will see the dashboard. There’s also &lt;a href="https://github.com/fauna/fauna-shell"&gt;Fauna shell&lt;/a&gt; if you love the shell environment. It allows you to create and/or modify resources on Fauna through the terminal.&lt;/p&gt;

&lt;p&gt;To use fauna shell, follow the below command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --global fauna-shell
fauna cloud-login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we’re ready to start exploring our data and experiment with queries in the Fauna dashboard. Open the dashboard, it will look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--imvO5rO---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9vaqyxdgq1fycrmhl52p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--imvO5rO---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9vaqyxdgq1fycrmhl52p.png" alt="AltText"&gt;&lt;/a&gt;&lt;br&gt;
We’ll go through the following simple steps to create a new fauna database using Fauna services. We start with naming our database. In this tutorial, we will name our database &lt;strong&gt;debt_tracker&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1WI6-fVQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mlpi1ih1pd8kq0b8tlm2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1WI6-fVQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mlpi1ih1pd8kq0b8tlm2.png" alt="AltText"&gt;&lt;/a&gt;&lt;br&gt;
The next step is to create a new data collection from the Fauna dashboard with the database created. Navigate to the &lt;strong&gt;Collection&lt;/strong&gt; tab on the side menu and create a new collection by clicking on the &lt;code&gt;NEW COLLECTION&lt;/code&gt; button.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--D_CGljir--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3gqcx5ubcuh6swbx0i5n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D_CGljir--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3gqcx5ubcuh6swbx0i5n.png" alt="AltText"&gt;&lt;/a&gt;&lt;br&gt;
We’ll then go ahead to give whatever name is well suited to our collection. Here we will also call it &lt;strong&gt;debt_tracker&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BqQ1gsHU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nutkjkv99blns3cerb96.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BqQ1gsHU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nutkjkv99blns3cerb96.png" alt="AltText"&gt;&lt;/a&gt;&lt;br&gt;
Next step is to grap our API key from the Security link on the sidebar. Click on the new key button to generate the API key we would be using for our application. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J5drfyAw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w7epytusnv2fqoy0aimp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J5drfyAw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w7epytusnv2fqoy0aimp.png" alt="AltText"&gt;&lt;/a&gt;&lt;br&gt;
The next screen will display the API key for the database we just created. Note to copy and store the API key at once. The key disappears once you leave the current page to another page. &lt;/p&gt;
&lt;h2&gt;
  
  
  Get started with Our Serverless Application
&lt;/h2&gt;

&lt;p&gt;Now we’ll learn the different working parts of building a serverless application so that you can easily go ahead and build a full application from the simple code units demonstrated within this tutorial.&lt;/p&gt;

&lt;p&gt;Let’s start by cloning the &lt;code&gt;serverless-crud&lt;/code&gt; project that would easily help us with a demo code template to perform CRUD functions with our application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;serverless install --url https://github.com/faunadb/serverless-crud
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Side note: please rename some of the files to represent the name of the application you’re building. Within this tutorial, the base name will change from &lt;code&gt;todos&lt;/code&gt; to &lt;code&gt;debt_tracker&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Once done with the cloning, we’ll change directory, cd into the service, the cloned folder, and then install all the dependencies needed within the folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd serverless-crud
npm install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once all the packages are fully installed, we will navigate into the &lt;code&gt;serverless.yml&lt;/code&gt; file and then look for the field with the name &lt;code&gt;MY_FAUNADB_SERVER_SECRET&lt;/code&gt; and replace the value with our API key we’ve copied and saved previously. Also, do the same as above for the &lt;code&gt;package.json&lt;/code&gt; file. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;serverless.yml&lt;/code&gt; file, which simply is a config file that is specific to Serverless framework, contains metadata of the utilities that will be looked into soon. Our focus will be mainly on the functions field and all its values. This contains the necessary information on how our serverless functions are structured to perform:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;functions:
  create:
    handler: handler.create
    events:
      - http:
          path: debt_tracker
          method: post
          cors: true
  readAll:
    handler: handler.readAll
    events:
      - http:
          path: debt_tracker
          method: get
          cors: true
  readOne: 
    handler: handler.readOne
    events:
      - http:
          path: debt_tracker/{id}
          method: get
          cors: true
  update:
    handler: handler.update
    events:
      - http:
          path: debt_tracker/{id}
          method: put
          cors: true
  delete:
    handler: handler.delete
    events:
      - http:
          path: debt_tracker/{id}
          method: delete
          cors: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code, easily explained, means look for folder &lt;code&gt;functions&lt;/code&gt; that contain a file: &lt;code&gt;handler.js&lt;/code&gt;. Within this file are defined utilities, functions, that are defined and exported for specific actions. We've five serverless functions from the above code that will perform the CRUD operation to our database that we had set up earlier within this tutorial. So let's navigate into the &lt;code&gt;handler.js&lt;/code&gt; file to explore the functions.&lt;/p&gt;

&lt;p&gt;Within the &lt;code&gt;handler.js&lt;/code&gt; file is where our serverless functions, defined within the same working directory with the &lt;code&gt;handler.js&lt;/code&gt; are imported to make different specific requests to the database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;("use strict");

const debt_trackerCreate = require("./todos-create.js");
const debt_trackerReadAll = require("./todos-read-all.js");
const debt_trackerReadOne = require("./todos-read-one.js");
const debt_trackerUpdate = require("./todos-update.js");
const debt_trackerDelete = require("./todos-delete.js");

module.exports.create = (event, context, callback) =&amp;gt; {
    debt_trackerCreate(event, (error, result) =&amp;gt; {
        const response = {
            statusCode: 200,
            headers: {
                "Access-Control-Allow-Origin": "*"
            },
            body: JSON.stringify(result)
        };
        context.succeed(response);
    });
};

module.exports.readAll = (event, context, callback) =&amp;gt; {
    debt_trackerReadAll(event, (error, result) =&amp;gt; {
        const response = {
            statusCode: 200,
            headers: {
                "Access-Control-Allow-Origin": "*"
            },
            body: JSON.stringify(result)
        };
        context.succeed(response);
    });
};

module.exports.readOne = (event, context, callback) =&amp;gt; {
    debt_trackerReadOne(event, (error, result) =&amp;gt; {
        const response = {
            statusCode: 200,
            headers: {
                "Access-Control-Allow-Origin": "*"
            },
            body: JSON.stringify(result)
        };
        context.succeed(response);
    });
};

module.exports.update = (event, context, callback) =&amp;gt; {
    debt_trackerUpdate(event, (error, result) =&amp;gt; {
        const response = {
            statusCode: 200,
            headers: {
                "Access-Control-Allow-Origin": "*"
            },
            body: JSON.stringify(result)
        };
        context.succeed(response);
    });
};

module.exports.delete = (event, context, callback) =&amp;gt; {
    debt_trackerDelete(event, (error, result) =&amp;gt; {
        const response = {
            statusCode: 200,
            headers: {
                "Access-Control-Allow-Origin": "*"
            },
            body: JSON.stringify(result)
        };
        context.succeed(response);
    });
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first function will automatically take object data and create a debt document within our database.  The second function reaches out to the database and fetches all the debt documents we have created. While for the third, fourth, and fifth functions will fetch, update or delete a particular debt document with the ID provided for it. &lt;/p&gt;

&lt;p&gt;Now we have made all these available, and the next would be to deploy our application to any cloud provider of your choice.  And simply perform API requests against the exposed endpoints within our application.&lt;/p&gt;

&lt;p&gt;To &lt;strong&gt;create&lt;/strong&gt; a debt document, run the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X POST https://XXXX.execute-api.region.amazonaws.com/dev/debt_tracker --data '{ "debt" : "Owing the UN a visit" }'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To &lt;strong&gt;read all&lt;/strong&gt; the debt documents, run the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl https://XXXX.execute-api.region.amazonaws.com/dev/debt_tracker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To &lt;strong&gt;read one&lt;/strong&gt; of the debt documents, run the command with an ID provided:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl https://XXXX.execute-api.region.amazonaws.com/dev/debt_tracker/&amp;lt;id&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To &lt;strong&gt;update one&lt;/strong&gt; of the debt documents, run the command with an ID provided:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X PUT https://XXXX.execute-api.region.amazonaws.com/dev/debt_tracker/&amp;lt;id&amp;gt; --data '{ "debt" : "Owing my travel agency" }'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To &lt;strong&gt;delete one&lt;/strong&gt; of the debt documents, run the command with an ID provided:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X DELETE https://XXXX.execute-api.region.amazonaws.com/dev/debt_tracker/&amp;lt;id&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This covers the samples to what our request to the endpoints would look like.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Congrats, you’ve made it to the end of this tutorial. As we’ve built this project, and look forward to building more projects using a serverless architecture, the choice of what tools/framework to use will always fall to Fauna and &lt;a href="https://www.serverless.com/"&gt;Serverless Framework&lt;/a&gt; with any cloud services provider. We can always look forward to the endless benefits, like the example of serverless code dynamically provisioning resources using FauanDB's multi-tenant QoS features and the easy integration of Fauna with other serverless components.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://fauna.com/"&gt;Fauna&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.serverless.com/"&gt;Serverless Application Framework&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.cloudflare.com/en-gb/learning/serverless/what-is-serverless/"&gt;Serverless Computing&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Integrating Fauna Into Preact WMR Application</title>
      <dc:creator>17th_streetCode</dc:creator>
      <pubDate>Wed, 16 Jun 2021 16:28:19 +0000</pubDate>
      <link>https://dev.to/ikehakinyemi/integrating-fauna-into-preact-wmr-application-4e9</link>
      <guid>https://dev.to/ikehakinyemi/integrating-fauna-into-preact-wmr-application-4e9</guid>
      <description>&lt;p&gt;In this tutorial, we’ll integrate Fauna into a Preact WMR application. We’ll perform CRUD actions to our database within the WMR application. Our focus will solely be on exploring Fauna CRUD actions within a Preact WMR application.&lt;/p&gt;

&lt;p&gt;While the development process is evolving for developers, there’s a need by many developers to have an all-in-one development tool that will make web application development faster and easier. &lt;a href="https://github.com/preactjs/wmr" rel="noopener noreferrer"&gt;WMR&lt;/a&gt; gives developers the added feature and advantage of building web applications based on the all-in-one development tool.&lt;/p&gt;

&lt;p&gt;In this tutorial, we will integrate Fauna into a Notes keeping application built using Preact WMR library. Let’s start by implementing the frontend part of the Notes application.&lt;/p&gt;

&lt;p&gt;Prerequisites&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A basic understanding of React and React hooks.&lt;/li&gt;
&lt;li&gt;Have Node installed on our local machine&lt;/li&gt;
&lt;li&gt;A basic understanding of JavaScript&lt;/li&gt;
&lt;li&gt;Have &lt;code&gt;yarn&lt;/code&gt; or &lt;code&gt;npm&lt;/code&gt; installed as a node package manager&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Implementing The Frontend Application
&lt;/h2&gt;

&lt;p&gt;We will implement the frontend part of the application by cloning a WMR project, and walk through the different parts of the project. We start by cloning an already built WMR application repository.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/IkehAkinyemi/preact-wmr-notes-app.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once done cloning the application, open the project in your choice of text editor. Within the project, our focus is on the ./public/api and ./public/config folders. Within these folders, we have our setup and connection to our database, that we’ll set up later within this tutorial. &lt;/p&gt;

&lt;p&gt;Next, we install &lt;a href="https://docs.fauna.com/fauna/current/drivers/javascript.html" rel="noopener noreferrer"&gt;Fauna’s JavaScript driver&lt;/a&gt;, this will help make CRUD actions to the database for fetching, deleting and also creating data on it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add faunadb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save faunadb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Within the &lt;code&gt;./public/config&lt;/code&gt; folder, we create a &lt;code&gt;db.js&lt;/code&gt;  file, and import the Fauna library. We proceed to set up our &lt;code&gt;client&lt;/code&gt; and &lt;code&gt;query&lt;/code&gt; variables to help us connect to our database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import faunadb from "faunadb";
const client = new faunadb.Client({ secret: process.env.REACT_APP_DB_KEY });
const q = faunadb.query;
export { client, q };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will generate our API key once we have our database set up later within this tutorial. Let’s proceed to define our CRUD actions within the &lt;code&gt;./public/api/index.js&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { client, q } from "../config/db";
const getAllNotes = client
  .query(q.Paginate(q.Match(q.Ref("indexes/all_notes"))))
  .then((res) =&amp;gt; {
    const noteRef = res.data;
    const getAllDataQuery = noteRef.map((ref) =&amp;gt; {
      return q.Get(ref);
    });
    return client.query(getAllDataQuery).then((data) =&amp;gt; data);
  })
  .catch((err) =&amp;gt; err.message);
const createNote = (note) =&amp;gt;
  client
    .query(q.Create(q.Collection("notes"), { data: { note } }))
    .then((ref) =&amp;gt; ref)
    .catch((err) =&amp;gt; err.message);
const deleteNote = (noteId) =&amp;gt;
  client
    .query(q.Delete(q.Ref(q.Collection("notes"), noteId)))
    .then((ref) =&amp;gt; ref)
    .catch((err) =&amp;gt; err.message);
export { getAllNotes, createNote, deleteNote };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we created and exported three different CRUD actions: &lt;code&gt;getAllNotes&lt;/code&gt;, &lt;code&gt;createNote&lt;/code&gt;, and &lt;code&gt;deleteNote&lt;/code&gt;. These will help us develop, obtain, and delete our Notes data from the database through some frontend actions that we will see later in the tutorial. Within the &lt;code&gt;getAllNotes&lt;/code&gt; action, our database set up would contain &lt;strong&gt;Indexes&lt;/strong&gt; with the name of &lt;code&gt;all_notes&lt;/code&gt;. This will help us group our note data, within the database, into a single group search. The createNote action records that our database would contain a &lt;strong&gt;Collection&lt;/strong&gt; named &lt;code&gt;notes&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We proceed to the &lt;code&gt;./public/pages/app/index.jsx&lt;/code&gt; file where we created &lt;strong&gt;JSX&lt;/strong&gt; elements that will help us markup and style our frontend application. And then import all our API functions to help us carry out our CRUD actions. We also define utility functions that will work with React hooks to get all the notes data from the database, create note data on the database, and delete a particular Note.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState, useEffect } from "preact/hooks";
import { FaTrash } from "react-icons/fa";
import { createNote, deleteNote, getAllNotes } from "../../api";
import styles from "./style.module.css";

export default function NoteApp() {
  const [Notes, setNotes] = useState([]);
  useEffect(() =&amp;gt; {
    getAllNotes.then((res) =&amp;gt; {
      setNote(res);
      console.log(res);
    });
  }, []);
  const [currNote, setcurrNote] = useState("");
  const addNote = (e, note_content) =&amp;gt; {
    Notes.push({
      id: Notes.length,
      note: note_content,
    });
    // createNote(note_content).then((res) =&amp;gt; {
    //   console.log("Expense details added to the database");
    // });
    setcurrNote("");
    e.preventDefault();
  };
  const deleteNoteItem = (note_idx) =&amp;gt; {
    const notes = Notes.filter((note) =&amp;gt; note.id !== note_idx);
    setNotes(notes);
    deleteNote(note_idx).then((res) =&amp;gt; res);
  };
  const extractNotes = () =&amp;gt;
    Object.values(Notes).map((note) =&amp;gt; (
      &amp;lt;li key={note.id} class={styles.noteItem}&amp;gt;
        &amp;lt;span
          class={styles.deleteIcon}
          onClick={(e) =&amp;gt; deleteNoteItem(note.id)}
        &amp;gt;
          &amp;lt;FaTrash size={20} color={"red"} /&amp;gt;
        &amp;lt;/span&amp;gt;
        {note.note}
      &amp;lt;/li&amp;gt;
    ));
  return (
    &amp;lt;section class={styles.wmr_app}&amp;gt;
      &amp;lt;h1&amp;gt;Preact WMR Note Application Built With Fauna&amp;lt;/h1&amp;gt;
      &amp;lt;div class={styles.inputArea}&amp;gt;
        &amp;lt;h3&amp;gt;Write and add your Notes.&amp;lt;/h3&amp;gt;
        &amp;lt;input
          class={styles.inputField}
          type="text"
          value={currNote}
          onChange={(e) =&amp;gt; setcurrNote(e.currentTarget.value)}
          onKeyUp={(e) =&amp;gt; (e.key == "Enter" ? addNote(currNote) : null)}
        /&amp;gt;
        &amp;lt;button class={styles.button} onClick={(e) =&amp;gt; addNote(e, currNote)}&amp;gt;
          Add
        &amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div class={styles.notes_list_wrapper}&amp;gt;
        &amp;lt;ul class={styles.unstyled_list}&amp;gt;{extractNotes()}&amp;lt;/ul&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/section&amp;gt;
  );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code, we define utility functions, &lt;code&gt;addNote&lt;/code&gt;, &lt;code&gt;deleteNoteItem&lt;/code&gt; and &lt;code&gt;extractNotes&lt;/code&gt;. The &lt;code&gt;addNote&lt;/code&gt; will be used to update our database with the new note item and update our frontend application. The &lt;code&gt;deleteNoteItem&lt;/code&gt; would be used to delete note items from the database, and also on the frontend part of the application. The &lt;code&gt;extractNote&lt;/code&gt; will help us extract the values of the notes we will get from the database. Our frontend application will look like the below UI with the predefined styles we have in the &lt;code&gt;./public/pages/app/styles.module.css&lt;/code&gt;: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs10l2iu6f833si5aa1dx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs10l2iu6f833si5aa1dx.png" alt="first photo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we have the frontend part of our application ready. Now, let’s integrate Fauna into our application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Integrating Fauna Into Our Application
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://fauna.com/" rel="noopener noreferrer"&gt;Fauna&lt;/a&gt; is a flexible, developer-friendly, transactional cloud database delivered as a secure Data API that provides two interfaces: GraphQL and the Fauna Query Language (FQL). It includes functionality to store collections, indexes, and other databases (multi-tenancy). To learn more about Fauna, visit the &lt;a href="https://docs.fauna.com/fauna/current/start/index.html" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We need to create the database for our Preact WMR application in Fauna’s dashboard. If you have not created an account on Fauna before now, create one &lt;a href="https://fauna.com/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Within the dashboard screen, press on the &lt;code&gt;NEW DATABASE&lt;/code&gt; button, and provide a name for the database then press the SAVE button. In this tutoria,l we call it &lt;strong&gt;notes_application&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq587wl5lu1kglyf5qjud.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq587wl5lu1kglyf5qjud.png" alt="Navigation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we create a Fauna collection to store data in the recently created database. A &lt;strong&gt;Collection&lt;/strong&gt; is similar to SQL tables containing similar characteristics, e.g. a user collection with information about users in the database. Click on the &lt;code&gt;NEW COLLECTION&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvon4qtp5qpblqihlisuv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvon4qtp5qpblqihlisuv.png" alt="Fauna's dashboard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once we click on the button, it will take us to a form where we’ll name our data collection. In this tutorial, we’ll call it &lt;strong&gt;notes&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsqz82iuaeupp4l50shnw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsqz82iuaeupp4l50shnw.png" alt="collection"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next we create the &lt;strong&gt;INDEXES&lt;/strong&gt; for the collection of the database. A Fauna index allows us to browse through data stored in a database collection based on specific attributes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdgnezml9qt3l1wnedu1c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdgnezml9qt3l1wnedu1c.png" alt="collection form"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We’ll click on the &lt;code&gt;NEW INDEX&lt;/code&gt; to create a new index for our database. We name ours &lt;strong&gt;all_notes&lt;/strong&gt;. Remember to select the current collection we’re creating the index for.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4w898t5pohl1ylrf8xpo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4w898t5pohl1ylrf8xpo.png" alt="index"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next navigate to the &lt;strong&gt;SECURITY&lt;/strong&gt; tab. By clicking on the &lt;code&gt;SECURITY&lt;/code&gt; button on the sidebar to generate an API key for our application. Click the &lt;code&gt;SAVE&lt;/code&gt; button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxplom6hvembz8btltq2c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxplom6hvembz8btltq2c.png" alt="security"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you have done this, Fauna will present you with your &lt;code&gt;Secret Key&lt;/code&gt;. Copy the key immediately and store it within our application or somewhere easily retrievable because it will only be displayed once.&lt;/p&gt;

&lt;p&gt;Now we’re done with the basic setup for our database. We can now go to our application and start creating, storing, getting, and deleting our notes.&lt;/p&gt;

&lt;p&gt;Our final frontend application will look like the UI below. The frontend application is ready to carry out our basic CRUD actions. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fim7jmebs95q5xs81gami.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fim7jmebs95q5xs81gami.png" alt="complete application"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our database will contain this data in an object with a &lt;code&gt;note&lt;/code&gt; field.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6cb51okktg21vy78r39s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6cb51okktg21vy78r39s.png" alt="database"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this tutorial, we built a Notes application with Fauna's serverless database and Preact WMR. We saw how easy it is to integrate Fauna into a Preact WMR application and got the chance to explore some of its core features and functionalities. Here’s my &lt;a href="https://twitter.com/IkehAkinyemi" rel="noopener noreferrer"&gt;Twitter handle&lt;/a&gt;, &lt;a class="mentioned-user" href="https://dev.to/ikehakinyemi"&gt;@ikehakinyemi&lt;/a&gt;, also my dev.to handle, I would love to answer your questions on this tutorial and also see you build with Fauna.&lt;/p&gt;

&lt;p&gt;The source code of this tutorial is available on &lt;a href="https://github.com/IkehAkinyemi/preact-wmr-notes-app" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Building Headless CMS With Fauna And Vercel Functions.</title>
      <dc:creator>17th_streetCode</dc:creator>
      <pubDate>Fri, 14 May 2021 09:57:33 +0000</pubDate>
      <link>https://dev.to/ikehakinyemi/building-headless-cms-with-fauna-and-vercel-functions-1kg4</link>
      <guid>https://dev.to/ikehakinyemi/building-headless-cms-with-fauna-and-vercel-functions-1kg4</guid>
      <description>&lt;p&gt;Written in connection with the &lt;a href="https://www2.fauna.com/write-with-fauna" rel="noopener noreferrer"&gt;Write With Fauna program&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Quick summary — &lt;em&gt;This article introduces the concept of the headless CMS, a backend-only content management system that allows developers to create, store, manage and publish the content over an API using the Fauna and Vercel functions. This improves the frontend-backend workflow, that enables developers to build excellent user experience quickly.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In this tutorial, we will learn and use headless CMS, Fauna, and Vercel functions to build a blogging platform, Blogify🚀. After that, you can easily build any web application using a headless CMS, Fauna and Vercel functions. &lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;According to &lt;a href="https://en.wikipedia.org/wiki/Content_management_system" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;, A content management system (CMS) is a computer software used to manage the creation and modification of digital content. CMS typically has two major components: a content management application (CMA), as the front-end user interface that allows a user, even with limited expertise, to add, modify, and remove content from a website without the intervention of a webmaster; and a content delivery application (CDA), that compiles the content and updates the website. &lt;/p&gt;

&lt;h3&gt;
  
  
  The Pros And Cons Of Traditional vs Headless CMS
&lt;/h3&gt;

&lt;p&gt;Choosing between these two can be quite confusing and complicated. But they both have potential advantages and drawbacks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Traditional CMS Pros&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Setting up your content on a traditional CMS is much easier as everything you need (content management, design, etc) are made available to you.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A lot of traditional CMS has drag and drop, making it easy for a person with no programming experience to work easily with them. It also has support for easy customization with zero to little coding knowledge.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Traditional CMS Cons&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The plugins and themes which the traditional CMS relies on may contain malicious codes or bugs and slow the speed of the website or blog.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The traditional coupling of the front-end and back-end definitely would more time and money for maintenance and customization.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Headless CMS Pros&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;There’s flexibility with choice of frontend framework to use since the frontend and backend are separated from each other, it makes it possible for you to pick which front-end technology suits your needs. It gives the freewill to choose the tools need to build the frontend—flexibility during the development stage.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deploying works easier with headless CMS. The applications (blogs, websites, etc) built with headless CMS can be easily be deployed to work on various displays such as web device, mobile devices, AR/VR devices.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Headless CMS Cons&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You are left with the worries of managing your back-end infrastructures, setting up the UI component of your site, app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Implementation of headless CMS are known to be more costly against the traditional CMS. Building headless CMS application that embodies analytics are not cost-effective.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://fauna.com/" rel="noopener noreferrer"&gt;&lt;strong&gt;Fauna&lt;/strong&gt;&lt;/a&gt; uses a preexisting infrastructure to build web applications without the usually setting up a custom API server. This efficiently helps to save time for developers, and the stress of choosing regions and configuring storage that exists among other databases; which is global/multi-region by default, are nonexistent with Fauna. All maintenance we need are actively taken care of by engineers and automated DevOps at Fauna. We will use Fauna as our &lt;em&gt;backend-only content management system&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros Of Using Fauna&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The ease to use and create a Fauna database instance from within development environment of the hosting platforms like Netlify or Vercel.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Great support for querying data via GraphQL or use  Fauna’s own query language. Fauna Query Language (FQL), for complex functions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Access data in multiple models including relational, document, graph and temporal.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Capabilities like built-in authentication, transparent scalability and multi-tenancy are fully available on Fauna.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add-on through Fauna Console as well as Fauna Shell makes it easy to manage database instance very easily.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Vercel Functions&lt;/strong&gt;, also known as Serverless Functions, according to the &lt;a href="https://vercel.com/docs/serverless-functions/introduction" rel="noopener noreferrer"&gt;docs&lt;/a&gt; are pieces of code written with &lt;a href="https://vercel.com/docs/serverless-functions/supported-languages#supported-languages" rel="noopener noreferrer"&gt;backend languages&lt;/a&gt; that take an HTTP request and provide a response.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;To take full advantage of this tutorial, ensure the following tools are available or installed on your local development environment:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Access to Fauna dashboard&lt;/li&gt;
&lt;li&gt;Basic knowledge of React and React Hooks&lt;/li&gt;
&lt;li&gt;Have &lt;a href="https://reactjs.org/docs/create-a-new-react-app.html" rel="noopener noreferrer"&gt;&lt;code&gt;create-react-app&lt;/code&gt;&lt;/a&gt; installed as a global package or use npx to bootstrap the project.&lt;/li&gt;
&lt;li&gt;Node.js version &amp;gt;= &lt;code&gt;12.x.x&lt;/code&gt; installed on your local machine.&lt;/li&gt;
&lt;li&gt;Ensure that &lt;code&gt;npm&lt;/code&gt; or &lt;code&gt;yarn&lt;/code&gt; is also installed as a package manager&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Database Setup With Fauna
&lt;/h2&gt;

&lt;p&gt;Sign in into your fauna account to get started with Fauna, or first register a new account using either email credentials/details or using an existing Github account as a new user. You can register for a new account &lt;a href="https://dashboard.fauna.com/accounts/register?utm_source=DevTo&amp;amp;utm_medium=referral&amp;amp;utm_campaign=WritewithFauna_NodeFauna_FIkechi" rel="noopener noreferrer"&gt;here&lt;/a&gt;. Once you have created a new account or signed in, you are going to be welcomed by the dashboard screen. We can also make use of the &lt;a href="https://github.com/fauna/fauna-shell" rel="noopener noreferrer"&gt;fauna shell&lt;/a&gt; if you love the shell environment. It easily allows you to create&lt;br&gt;
and/or modify resources on Fauna through the terminal.&lt;/p&gt;

&lt;p&gt;Using the fauna shell, the command is:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --global fauna-shell
fauna cloud-login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;But we will use the website throughout this tutorial. Once signed in, the dashboard screen welcomes you:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feowwocl1r62wi87yw0e2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feowwocl1r62wi87yw0e2.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we are logged in or have our accounts created, we can go ahead to create our Fauna. We’ll go through following simple steps to create the new fauna database using Fauna services. We start with naming our database, which we’ll use as our content management system. In this tutorial, we will name our database &lt;strong&gt;blogify&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsuyyfxo0xcs5gzqjy7ak.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsuyyfxo0xcs5gzqjy7ak.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With the database created, next step is to create a new data collection from the Fauna dashboard. Navigate to the Collection tab on the side menu and create a new collection by clicking on the &lt;code&gt;NEW COLLECTION&lt;/code&gt; button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd7m021xnxd2c0vts96cg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd7m021xnxd2c0vts96cg.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We’ll then go ahead to give whatever name well suiting to our collection. Here we will call it  &lt;em&gt;blogify_posts&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F91m031umkll276y3yxro.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F91m031umkll276y3yxro.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next step in getting our database ready is to create a new &lt;code&gt;index&lt;/code&gt;. Navigate to the &lt;em&gt;Indexes&lt;/em&gt; tab to create an index. Searching documents in Fauna can be done by using &lt;code&gt;indexes&lt;/code&gt;, specifically by matching inputs against an index’s &lt;code&gt;terms&lt;/code&gt; field. Click on the &lt;code&gt;NEW INDEX&lt;/code&gt; button to create an index. Once in create index screen, fill out the form: selecting the collection we’ve created previously, then giving a name to our index. In this tutorial, we will name ours &lt;em&gt;all_posts&lt;/em&gt;. We can now save our index.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp6u8j47jwk5qj4azshr4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp6u8j47jwk5qj4azshr4.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After creating an index, now it’s time to create our &lt;strong&gt;DOCUMENT&lt;/strong&gt;, this will contain the contents/data we want to use for our CMS website. Click on the &lt;code&gt;NEW DOCUMENT&lt;/code&gt;  button to get started. With the text editor to create our document, we’ll create an object data to serve our needs for the website.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjiboync1t1f8fcpy2mzf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjiboync1t1f8fcpy2mzf.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above &lt;code&gt;post&lt;/code&gt; object represents the unit data we need to create our blog post. Your choice of data can be so different from what we have here, serving the purpose whatever you want it for within your website. You can create as much document you may need for your CMS website. To keep things simple, we just have three blog posts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6h6t6fkvb3hz69c2khn8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6h6t6fkvb3hz69c2khn8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have our database setup complete to our choice, we can move on to create our React app, the frontend.&lt;/p&gt;
&lt;h2&gt;
  
  
  Create A New React App And Install Dependencies
&lt;/h2&gt;

&lt;p&gt;For the frontend development, we will need dependencies such as &lt;code&gt;FaunaDB SDK&lt;/code&gt;, &lt;code&gt;styled-components&lt;/code&gt; and &lt;code&gt;vercel&lt;/code&gt; in our React app. We will use the &lt;code&gt;styled-components&lt;/code&gt; for the UI styling, use the &lt;code&gt;vercel&lt;/code&gt; within our terminal to host our application. The &lt;code&gt;FaunaDB SDK&lt;/code&gt; would be used to access our contents at the database we had setup. You can always replace the &lt;code&gt;styled-components&lt;/code&gt; for whatever library you decide to use for your UI styling. Also use any UI framework or library you preferred to others.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app blogify
# install dependencies once directory is done/created
yarn add faunadb styled-components
# install vercel globally
yarn global add vercel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;faunadb&lt;/code&gt; package is Fauna JavaScript driver for Fauna. The library &lt;code&gt;styled-components&lt;/code&gt; allows you to write actual CSS code to style your components. Once done with all the installation for the project dependencies, check the &lt;code&gt;package.json&lt;/code&gt; file to confirm all installation was done &lt;br&gt;
successfully.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbkq3takuf7p9ef9pcqhw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbkq3takuf7p9ef9pcqhw.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let’s start an actual building of our blog website UI. We’ll start with the header section. We will create a &lt;code&gt;Navigation&lt;/code&gt; component within the &lt;code&gt;components&lt;/code&gt; folder inside the &lt;code&gt;src&lt;/code&gt; folder, &lt;code&gt;src/components&lt;/code&gt;, to contain our blog name, Blogify🚀.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
import styled from "styled-components";
function Navigation() {
  return (
    &amp;lt;Wrapper&amp;gt;
      &amp;lt;h1&amp;gt;Blogify🚀&amp;lt;/h1&amp;gt;
    &amp;lt;/Wrapper&amp;gt;
  );
}
const Wrapper = styled.div`
  background-color: #23001e;
  color: #f3e0ec;
  padding: 1.5rem 5rem;
  &amp;amp; &amp;gt; h1 {
    margin: 0px;
  }
`;
export default Navigation;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After being imported within the &lt;code&gt;App&lt;/code&gt; components, the above code coupled with the stylings through the &lt;code&gt;styled-components&lt;/code&gt; library, will turn out to look like the below UI:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5orvlbtc2p5b5ilyz595.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5orvlbtc2p5b5ilyz595.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now time to create the body of the website, that will contain the &lt;code&gt;post&lt;/code&gt; data from our database. We structure a component, called Posts, which will contains our blog posts created on the backend.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
import styled from "styled-components";
function Posts() {
  return (
    &amp;lt;Wrapper&amp;gt;
      &amp;lt;h3&amp;gt;My Recent Articles&amp;lt;/h3&amp;gt;
      &amp;lt;div className="container"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;/Wrapper&amp;gt;
  );
}
const Wrapper = styled.div`
  margin-top: 3rem;
  padding-left: 5rem;
  color: #23001e;
  &amp;amp; &amp;gt; .container {
    display: flex;
    flex-wrap: wrap;
  }
  &amp;amp; &amp;gt; .container &amp;gt; div {
    width: 50%;
    padding: 1rem;
    border: 2px dotted #ca9ce1;
    margin-bottom: 1rem;
    border-radius: 0.2rem;
  }
  &amp;amp; &amp;gt; .container &amp;gt; div &amp;gt; h4 {
    margin: 0px 0px 5px 0px;
  }
  &amp;amp; &amp;gt; .container &amp;gt; div &amp;gt; button {
    padding: 0.4rem 0.5rem;
    border: 1px solid #f2befc;
    border-radius: 0.35rem;
    background-color: #23001e;
    color: #ffffff;
    font-weight: medium;
    margin-top: 1rem;
    cursor: pointer;
  }
  &amp;amp; &amp;gt; .container &amp;gt; div &amp;gt; article {
    margin-top: 1rem;
  }
`;
export default Posts;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code contains styles for JSX that we’ll still create once we start querying for data from the backend to the frontend. &lt;/p&gt;

&lt;h2&gt;
  
  
  Integrate Fauna SDK Into Our React App
&lt;/h2&gt;

&lt;p&gt;To integrate the &lt;code&gt;faunadb&lt;/code&gt; client with the React app, you have to make an initial connection from the app. Create a new file &lt;code&gt;db.js&lt;/code&gt; at the directory path &lt;code&gt;src/config/&lt;/code&gt;. Then import the &lt;code&gt;faunadb&lt;/code&gt; driver and define a new client.&lt;br&gt;
The &lt;code&gt;secret&lt;/code&gt; passed as the argument to the &lt;code&gt;faunadb.Client()&lt;/code&gt; method is going to hold the access key from &lt;code&gt;.env&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import faunadb from 'faunadb';
const client = new faunadb.Client({
  secret: process.env.REACT_APP_DB_KEY,
});
const q = faunadb.query;
export { client, q };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside the &lt;code&gt;Posts&lt;/code&gt; component create a state variable called &lt;code&gt;posts&lt;/code&gt; using &lt;code&gt;useState&lt;/code&gt; React Hooks with a default value of an array. It is going to store the value of the content we’ll get back from our database using the &lt;code&gt;setPosts&lt;/code&gt; function.&lt;br&gt;
Then define a second state variable, &lt;code&gt;visible&lt;/code&gt;, with a default value of &lt;code&gt;false&lt;/code&gt;, that we’ll use to hide or show more post content using the &lt;code&gt;handleDisplay&lt;/code&gt; function that would be triggered by a button we’ll add later in the tutorial.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function App() {
  const [posts, setPosts] = useState([]);
  const [visible, setVisibility] = useState(false);
  const handleDisplay = () =&amp;gt; setVisibility(!visible);
  // ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Creating A Serverless Function By Writing Queries
&lt;/h2&gt;

&lt;p&gt;Since our blog website is going to perform only one operation, that’s to get the data/contents we created on the database, let’s create a new directory called &lt;code&gt;src/api/&lt;/code&gt; and inside it, we create a new file called &lt;code&gt;index.js&lt;/code&gt;. Making the request with ES6, we’ll use &lt;code&gt;import&lt;/code&gt;  to import the &lt;code&gt;client&lt;/code&gt; and the &lt;code&gt;query&lt;/code&gt; instance from the &lt;code&gt;config/db.js&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const getAllPosts = client
  .query(q.Paginate(q.Match(q.Ref('indexes/all_posts'))))
    .then(response =&amp;gt; {
      const expenseRef = response.data;
      const getAllDataQuery = expenseRef.map(ref =&amp;gt; {
        return q.Get(ref);
      });
     return client.query(getAllDataQuery).then(data =&amp;gt; data);
      })
    .catch(error =&amp;gt; console.error('Error: ', error.message));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  })
  .catch(error =&amp;gt; console.error('Error: ', error.message));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The query above to the database is going to return a &lt;code&gt;ref&lt;/code&gt; that we can map over to get the actual results need for the application. We’ll make sure to append the &lt;code&gt;catch&lt;/code&gt; that will help check for an error while querying the database, so we can log it out.&lt;/p&gt;

&lt;p&gt;Next is to display all the data returned from our CMS, database—from the Fauna collection. We’ll do so by invoking the query &lt;code&gt;getAllPosts&lt;/code&gt; from the &lt;code&gt;./api/index.js&lt;/code&gt; file inside the &lt;code&gt;useEffect&lt;/code&gt; Hook inside our &lt;code&gt;Posts&lt;/code&gt; component. This is because when the &lt;code&gt;Posts&lt;/code&gt; component renders for the first time, it iterates over the data, checking if there are any post in the database:&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; {
    getAllPosts.then((res) =&amp;gt; {
      setPosts(res);
      console.log(res);
    });
  }, []);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open the browser’s console to inspect the data returned from the database. If all things being right, and you’re closely following, the return data should look like the below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftlih6s10fd4jqd4nmz8p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftlih6s10fd4jqd4nmz8p.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With these data successfully returned from the database, we can now complete our &lt;code&gt;Posts&lt;/code&gt; components, adding all necessary JSX elements that we’ve styled using &lt;code&gt;styled-components&lt;/code&gt; library. We’ll use JavaScript &lt;code&gt;map&lt;/code&gt; to loop over the &lt;code&gt;posts&lt;/code&gt; state, array, only when the array is not empty:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useEffect, useState } from "react";
import styled from "styled-components";
import { getAllPosts } from "../api";

function Posts() {
  useEffect(() =&amp;gt; {
    getAllPosts.then((res) =&amp;gt; {
      setPosts(res);
      console.log(res);
    });
  }, []);

  const [posts, setPosts] = useState([]);
  const [visible, setVisibility] = useState(false);
  const handleDisplay = () =&amp;gt; setVisibility(!visible);

  return (
    &amp;lt;Wrapper&amp;gt;
      &amp;lt;h3&amp;gt;My Recent Articles&amp;lt;/h3&amp;gt;
      &amp;lt;div className="container"&amp;gt;
        {posts &amp;amp;&amp;amp;
          posts.map((post) =&amp;gt; (
            &amp;lt;div key={post.ref.id} id={post.ref.id}&amp;gt;
              &amp;lt;h4&amp;gt;{post.data.post.title}&amp;lt;/h4&amp;gt;
              &amp;lt;em&amp;gt;{post.data.post.date}&amp;lt;/em&amp;gt;
              &amp;lt;article&amp;gt;
                {post.data.post.mainContent}
                &amp;lt;p style={{ display: visible ? "block" : "none" }}&amp;gt;
                  {post.data.post.subContent}
                &amp;lt;/p&amp;gt;
              &amp;lt;/article&amp;gt;
              &amp;lt;button onClick={handleDisplay}&amp;gt;
                {visible ? "Show less" : "Show more"}
              &amp;lt;/button&amp;gt;
            &amp;lt;/div&amp;gt;
          ))}
      &amp;lt;/div&amp;gt;
    &amp;lt;/Wrapper&amp;gt;
  );
}

const Wrapper = styled.div`
  margin-top: 3rem;
  padding-left: 5rem;
  color: #23001e;
  &amp;amp; &amp;gt; .container {
    display: flex;
    flex-wrap: wrap;
  }
  &amp;amp; &amp;gt; .container &amp;gt; div {
    width: 50%;
    padding: 1rem;
    border: 2px dotted #ca9ce1;
    margin-bottom: 1rem;
    border-radius: 0.2rem;
  }
  &amp;amp; &amp;gt; .container &amp;gt; div &amp;gt; h4 {
    margin: 0px 0px 5px 0px;
  }
  &amp;amp; &amp;gt; .container &amp;gt; div &amp;gt; button {
    padding: 0.4rem 0.5rem;
    border: 1px solid #f2befc;
    border-radius: 0.35rem;
    background-color: #23001e;
    color: #ffffff;
    font-weight: medium;
    margin-top: 1rem;
    cursor: pointer;
  }
  &amp;amp; &amp;gt; .container &amp;gt; div &amp;gt; article {
    margin-top: 1rem;
  }
`;

export default Posts;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the complete code structure above, our blog website, Blogify🚀, will look like the below UI:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftbfnge7bv9knk5byijjk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftbfnge7bv9knk5byijjk.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploying To Vercel
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://vercel.com/cli" rel="noopener noreferrer"&gt;&lt;strong&gt;Vercel CLI&lt;/strong&gt;&lt;/a&gt; provides a set of commands that allow you to deploy and manage your projects. The following steps will get your project hosted from your terminal on vercel platform fast and easy:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vercel login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Follow the instructions to login into your vercel account on the terminal&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vercel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Using the &lt;code&gt;vercel&lt;/code&gt; command from the root of a project directory. This will prompt questions that we will provide answers to depending on what’s asked.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vercel
? Set up and deploy “~/Projects/JavaScript/React JS/blogify”? [Y/n] 
? Which scope do you want to deploy to? ikehakinyemi
? Link to existing project? [y/N] n
? What’s your project’s name? (blogify) 
  # click enter if you don't want to change the name of the project
? In which directory is your code located? ./ 
  # click enter if you running this deployment from root directory
? ? Want to override the settings? [y/N] n
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will deploy your project to vercel. Visit your vercel account to complete any other setup needed for CI/CD purpose.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I’m glad you followed the tutorial to this point, hope you’ve learned how to use Fauan as Headless CMS. The combination of Fauna with Headless CMS concepts you can build great web application, from e-commerce application to Notes keeping application, any web application that needs data to be stored and retrieved for use on the frontend. Here’s the &lt;a href="https://github.com/IkehAkinyemi/blogify" rel="noopener noreferrer"&gt;GitHub link&lt;/a&gt; to code sample we used within our tutorial, and the &lt;a href="https://blogify-one.vercel.app/" rel="noopener noreferrer"&gt;live demo&lt;/a&gt; which is hosted on vercel.&lt;/p&gt;

&lt;h2&gt;
  
  
  Related Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://en.wikipedia.org/wiki/Content_management_system" rel="noopener noreferrer"&gt;Content Management System&lt;/a&gt; (CSM)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.fauna.com/fauna/current/tutorials/crud.html#delete" rel="noopener noreferrer"&gt;Fauna CRUD docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fauna.com/blog/the-worlds-best-serverless-database-now-with-native-graphql" rel="noopener noreferrer"&gt;Fauna with GraphQL&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.fauna.com/fauna/current/tutorials/indexes/search.html" rel="noopener noreferrer"&gt;Indexes in Fauna&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://vercel.com/cli" rel="noopener noreferrer"&gt;Vercel CLI&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>serverless</category>
      <category>fauna</category>
      <category>database</category>
      <category>react</category>
    </item>
  </channel>
</rss>
