<?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>Forem: Pratham 👨‍💻✨</title>
    <description>The latest articles on Forem by Pratham 👨‍💻✨ (@prathkum).</description>
    <link>https://forem.com/prathkum</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%2F388415%2F353738ac-8f41-40bc-9ca3-d48c7a850d6e.jpeg</url>
      <title>Forem: Pratham 👨‍💻✨</title>
      <link>https://forem.com/prathkum</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/prathkum"/>
    <language>en</language>
    <item>
      <title>Build an Image-to-Text Extractor Application using API</title>
      <dc:creator>Pratham 👨‍💻✨</dc:creator>
      <pubDate>Fri, 24 Sep 2021 20:30:23 +0000</pubDate>
      <link>https://forem.com/rapidapi/build-an-image-to-text-extractor-application-using-api-5b7h</link>
      <guid>https://forem.com/rapidapi/build-an-image-to-text-extractor-application-using-api-5b7h</guid>
      <description>&lt;p&gt;Text extraction is a process in which we extract ASCII characters from the image or a scanned document. This kind of application has a wide range of scope, including text recognition which further helps in various Machine Learning algorithms.  &lt;/p&gt;

&lt;p&gt;In this article, we will build a simple yet powerful Text Extraction application using Pen to &lt;a href="https://rapidapi.com/serendi/api/pen-to-print-handwriting-ocr/?utm_source=dev.to%2FRapidAPI&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;Print - Handwriting OCR API and React&lt;/a&gt;.  &lt;/p&gt;

&lt;h2&gt;
  
  
  How to connect to the Facial Text Analysis API
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://rapidapi.com/hub?utm_source=dev.to%2FRapidAPI&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;RapidAPI&lt;/a&gt; handles all the API development things very effectively. You don't need to worry about any complicated stuff related to APIs like rate-limiting factors, authentication, and authorization. You just need to register on RapidAPI Hub if you want to use any API. RapidAPI provides you a single API key using which you can access over 35,000 APIs conveniently.   &lt;/p&gt;

&lt;p&gt;Go to &lt;a href="https://rapidapi.com/hub?utm_source=dev.to%2FRapidAPI&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;RapidAPI Hub&lt;/a&gt; and create a free account.   &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%2Fi2bmz2oyq6j5rl9xswa8.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%2Fi2bmz2oyq6j5rl9xswa8.png" alt="sign up page of RapidAPI Hub"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The majority of the APIs offer a freemium plan. You don't even need to add credit card details to access them. Let's choose the best-suited &lt;a href="https://rapidapi.com/serendi/api/pen-to-print-handwriting-ocr/pricing/?utm_source=dev.to%2FRapidAPI&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;pricing plan&lt;/a&gt; for Pen to Print - Handwriting OCR.  &lt;/p&gt;

&lt;p&gt;The Basic plan of &lt;a href="https://rapidapi.com/serendi/api/pen-to-print-handwriting-ocr/?utm_source=dev.to%2FRapidAPI&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;Pen to Print - Handwriting OCR&lt;/a&gt; is free but keep in mind that it only offers 100 API calls per month. You can always change the plan according to your needs. Just click on the "Subscribe" button of the Basic plan.   &lt;/p&gt;

&lt;p&gt;Now we are good to create a Text Extraction App using this API.   &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%2Fv0p0ljyeg5krh53nuiiu.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%2Fv0p0ljyeg5krh53nuiiu.png" alt="pricing page of Pen to Print = Handwriting OCR API"&gt;&lt;/a&gt;   &lt;/p&gt;

&lt;h2&gt;
  
  
  Play around with Pen to Print - Handwriting OCR API
&lt;/h2&gt;

&lt;p&gt;Once you subscribe, you can test the API and check the response this &lt;a href="https://rapidapi.com/serendi/api/pen-to-print-handwriting-ocr/?utm_source=dev.to%2FRapidAPI&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;Pen to Print - Handwriting OCR&lt;/a&gt; API returns. You can test multiple endpoints with different parameters using the API playground. Let's try to dig in with our current API to integrate it with our application.   &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%2Fi2exzy2j72f4uso2x4r1.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%2Fi2exzy2j72f4uso2x4r1.png" alt="homepage of pen to print - handwriting OCR"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Endpoints&lt;br&gt;
Here, you can take a quick look at the endpoints an interface supports. You can also search for a distinct endpoint.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Documentation&lt;br&gt;
Here, you can access and change all the necessary details required to test an endpoint. For example, you can pass values in the different parameters in the documentation section.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Code&lt;br&gt;
Every developer wants and loves this section. You can copy-paste the code directly from here. RapidAPI supports 20 programming languages with 40 different libraries.   &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The &lt;a href="https://rapidapi.com/serendi/api/pen-to-print-handwriting-ocr/?utm_source=dev.to%2FRapidAPI&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;Pen to Print - Handwriting OCR&lt;/a&gt; has only one endpoint which lets us make a POST request after uploading the image file from local storage. &lt;/p&gt;

&lt;p&gt;Scroll down a little bit in the documentation section. You will find a Request Body section, here you can pass all the necessary parameters. Upload an image from your device to test this API.   &lt;/p&gt;

&lt;p&gt;Great, we are all set to hit the "Test Endpoint" button.&lt;/p&gt;

&lt;p&gt;![test pen to print &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%2F9v5vc6cnsy5x6bk3xj6t.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%2F9v5vc6cnsy5x6bk3xj6t.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;handwriting OCR ](&lt;a href="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ula5x28rmm9ucwpivinb.png" rel="noopener noreferrer"&gt;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ula5x28rmm9ucwpivinb.png&lt;/a&gt;)
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After clicking the "Test Endpoint" button, you will see the endpoint (API) result in the third section of the API Playground. &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%2Fz7sg1xa5x422r1w18yb2.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%2Fz7sg1xa5x422r1w18yb2.png" alt="response of pen to print - Handwriting OCR"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the response body (returned data from the server) you will get a &lt;code&gt;value&lt;/code&gt; key that contains all the text present in the image.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Integrate Pen to Print - Handwriting OCR API into Your React Application
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://reactjs.org/" rel="noopener noreferrer"&gt;React&lt;/a&gt; is a front-end JavaScript library for building user interfaces. In this article, you will learn how to integrate an API into your React application and build a text extraction application. Just follow the steps below:  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Create a React Application&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Create React App is the simplest way to set up a React application by running one command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-react-app image-to-text 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will need to have Node.js (version &amp;gt;= 6) on your local machine. If you haven't, just download it for free.  &lt;/p&gt;

&lt;p&gt;Create-react-app command will create a folder for you with all the necessary files and folders required for a React application. You will get a &lt;code&gt;node_modules&lt;/code&gt;, &lt;code&gt;public&lt;/code&gt; and &lt;code&gt;src&lt;/code&gt; folder.&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%2Fpgw9djoxxplb9mz4gp2s.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%2Fpgw9djoxxplb9mz4gp2s.png" alt="file structure of React app"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Create a Form&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We want a form in our application where users can upload the image in order to extract text. We just need a file input field and a submit button in the form.  &lt;/p&gt;

&lt;p&gt;Go to your project folder (image-to-text that we just created in the first step) and you'll find that React created a bunch of other folders and files for us. We don't need to check them all right now.  &lt;/p&gt;

&lt;p&gt;Go to the &lt;code&gt;image-to-text folder &amp;gt; src &amp;gt; App.js&lt;/code&gt; file and create a form with a file input field and a submit button.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Image to Text Extractor&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;form&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"file"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Extract Text"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;form&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the application to check the output by running the following command from the root of the project and go to &lt;a href="https://localhost:3000" rel="noopener noreferrer"&gt;https://localhost:3000&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;npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2F7cc4o17r47869kzs8sww.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%2F7cc4o17r47869kzs8sww.png" alt="text extractor application"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Copy-paste the code snippet from RapidAPI Hub&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We are all set to integrate Text Analysis API code into our application. You don't even need to write the code. RapidAPI provides the code snippet in 20 programming languages with 40 libraries' support.   &lt;/p&gt;

&lt;p&gt;Go to the &lt;a href="https://rapidapi.com/serendi/api/pen-to-print-handwriting-ocr/?utm_source=dev.to%2FRapidAPI&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;Pen to Print - Handwriting OCR&lt;/a&gt; API homepage and copy the code snippet from the Copy Snippets section of the API playground.   &lt;/p&gt;

&lt;p&gt;Select the JavaScript language and &lt;a href="https://github.com/axios/axios" rel="noopener noreferrer"&gt;axios&lt;/a&gt; method from the dropdown menu and click on the "Copy Code" 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%2Fq8l1qj3tntyngowpofhz.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%2Fq8l1qj3tntyngowpofhz.png" alt="copy code snippet of Pen to Print - Handwriting OCR API"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create a &lt;code&gt;handleFormSubmit()&lt;/code&gt; function in the App.js file and paste the code inside that function. &lt;/p&gt;

&lt;p&gt;We need to install the &lt;a href="https://www.npmjs.com/package/axios" rel="noopener noreferrer"&gt;axios&lt;/a&gt; library first in order to use it in our application. Run the following command from the root of the project.&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 axios 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Let the user upload the image and extract the text&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We are almost done! We just need to validate the form so that the user can enter the text to get the result.   &lt;/p&gt;

&lt;p&gt;Let's complete the form first. Create two &lt;code&gt;useState&lt;/code&gt; hooks in the App.js file, one for handling the state binary image file to make the API call, and the second is for displaying the image that user uploads.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;previewImage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setPreviewImage&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;imageFile&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setImageFile&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;({});&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;form&lt;/span&gt; &lt;span class="nx"&gt;onSubmit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleFormSubmit&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;file&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;onChange&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleFileInputChange&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;submit&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Extract Text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/form&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Call a function &lt;code&gt;handleFileInputChage&lt;/code&gt; whenever a user uploads the new image file. Inside that function, we need to set the states so that we can display the preview image and convert the image file to binary in order to make the API call.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;handleFileInputChange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;setImageFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;files&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
  &lt;span class="nf"&gt;setPreviewImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createObjectURL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;files&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As simple as that, we are setting the binary format inside &lt;code&gt;imageFile&lt;/code&gt; and object URL inside &lt;code&gt;previewImage&lt;/code&gt; using &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL" rel="noopener noreferrer"&gt;URL.createObjectURL&lt;/a&gt; method.   &lt;/p&gt;

&lt;p&gt;Let's create another useState hook for storing the response that the server returns.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setText&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Modify the &lt;code&gt;handleFormSubmit&lt;/code&gt; function a little bit to store the &lt;code&gt;text&lt;/code&gt; response string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;axios&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Render the extracted text on the webpage when the API successfully returns the data. You can do this by adding some paragraph tags inside the return method in the App.js file.   &lt;/p&gt;

&lt;p&gt;If you missed some parts, this is how the entire App.js file looks like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;axios&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;previewImage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setPreviewImage&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;imageFile&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setImageFile&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;({});&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setText&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;handleFileInputChange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setImageFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;files&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="nf"&gt;setPreviewImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createObjectURL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;files&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]));&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;handleFormSubmit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;form&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FormData&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Session&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;srcImg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;imageFile&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://pen-to-print-handwriting-ocr.p.rapidapi.com/recognize/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;content-type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;multipart/form-data&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;x-rapidapi-host&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;pen-to-print-handwriting-ocr.p.rapidapi.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;x-rapidapi-key&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;REACT_APP_API_KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;form&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="nx"&gt;axios&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;setText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;})&lt;/span&gt;
     &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
     &lt;span class="p"&gt;});&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"App"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Image to Text Extractor&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;previewImage&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;form&lt;/span&gt; &lt;span class="na"&gt;onSubmit&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleFormSubmit&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"file"&lt;/span&gt; &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleFileInputChange&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Extract Text"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
       &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;form&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
       &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One important thing to note here is that we have passed the API key as&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;x-rapidapi-key&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;REACT_APP_API_KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;x-rapidapi-key&lt;/code&gt; is your API key that RapidAPI provides using which you can access over 35,000 excellent APIs. It's always recommended to pass the API key as an environment variable because it's a confidential thing. Anyone can use your API subscription if they have your API key.   &lt;/p&gt;

&lt;p&gt;Create a &lt;code&gt;.env&lt;/code&gt; inside the &lt;code&gt;image-to-text&lt;/code&gt; folder and add your API key inside REACT_APP_API_KEY(you can call it whatever you want but it should start with the prefix REACT_APP_ ) variable. Now you can access it inside the App.js file as process.env.REACT_APP_API_KEY.    &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Output&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yay! Run the &lt;code&gt;npm start&lt;/code&gt; command, and you'll see the result at &lt;a href="http://localhost:3000/" rel="noopener noreferrer"&gt;http://localhost:3000/&lt;/a&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%2Fspkh8y45j3l3j7zebneo.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%2Fspkh8y45j3l3j7zebneo.png" alt="image to text extractor application"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can check the working project &lt;a href="https://codesandbox.io/s/image-to-text-ipgvn" rel="noopener noreferrer"&gt;here&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;You can add styling using CSS to make it look more appealing.&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%2Fp0g2p5zjgik3407e0up0.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%2Fp0g2p5zjgik3407e0up0.png" alt="final result of text extractor application"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go to &lt;a href="https://rapidapi.com/hub?utm_source=dev.to%2FRapidAPI&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;RapidAPI Hub&lt;/a&gt; and create a free account to get your API key. The fun part is that you can use over 35,000 excellent APIs with just one API key. So it's worth creating a free account on RapidAPI Hub.     &lt;/p&gt;

&lt;p&gt;Feel free to drop your suggestions, feedback, and doubts down below. We love checking them out.  &lt;/p&gt;

&lt;p&gt;With that said, we hope you enjoy this article. Peace out!! Keep coding! We will catch you with the next excellent project idea.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Create a Text Sentiment Analysis App using React</title>
      <dc:creator>Pratham 👨‍💻✨</dc:creator>
      <pubDate>Fri, 17 Sep 2021 21:22:20 +0000</pubDate>
      <link>https://forem.com/rapidapi/how-to-create-a-text-sentiment-analysis-app-using-react-88i</link>
      <guid>https://forem.com/rapidapi/how-to-create-a-text-sentiment-analysis-app-using-react-88i</guid>
      <description>&lt;p&gt;Text sentiment analysis is a machine learning and natural language processing technique to analyze the text sentiment of a writer. The sentiment can be positive, negative, or neutral. Text sentiment analysis, also known as opinion mining, is a deep area of research. In this blog, we will make a text sentiment analysis application using an API available on RapidAPI Hub.   &lt;/p&gt;

&lt;p&gt;&lt;a href="https://rapidapi.com/gaurmanojkumar530/api/text-analysis12/?utm_source=dev.to%2Frapidapi&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;Text Analysis&lt;/a&gt; is an excellent API available on &lt;a href="https://rapidapi.com/hub?utm_source=dev.to%2Frapidapi&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;RapidAPI Hub&lt;/a&gt; using which you can create a text analysis application. &lt;a href="https://rapidapi.com/gaurmanojkumar530/api/text-analysis12/?utm_source=dev.to%2Frapidapi&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;Text Analysis&lt;/a&gt; has several other endpoints as well which let you perform sentiment-analysis, text-summarization, language-detection, article-extraction, named-entity-recognition on text. You can also analyze text from a whole website or from documents and images using this API.     &lt;/p&gt;

&lt;p&gt;We will be focusing on the text analysis endpoint in this particular article. Let’s get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to connect to the Facial Text Analysis API
&lt;/h2&gt;

&lt;p&gt;RapidAPI handles all the API development things very effectively. You don’t need to worry about any complicated stuff related to API like rate-limiting factors, authentication, authorization. RapidAPI does all the communications by itself. You just need to register on RapidAPI Hub if you want to use any API. RapidAPI provides you a single API key using which you can access over 35,000 APIs conveniently.&lt;br&gt;
Go to &lt;a href="https://rapidapi.com/hub?utm_source=dev.to%2Frapidapi&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;RapidAPI Hub&lt;/a&gt; and create a free account.&lt;/p&gt;

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

&lt;p&gt;The majority of the APIs offer a freemium plan. You don’t even need to add credit card details to access them. Visit &lt;a href="https://rapidapi.com/gaurmanojkumar530/api/text-analysis12/?utm_source=dev.to%2Frapidapi&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;Text Analysis&lt;/a&gt; API on RapidAPI Hub. It is completely free and has only one subscription plan which allows you to make 100 API calls per second.&lt;/p&gt;

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

&lt;p&gt;Just click on the “Subscribe” button of the Basic plan.&lt;br&gt;
Now we are good to create a Text Sentiment Analysis App using React and this API.&lt;/p&gt;
&lt;h2&gt;
  
  
  Play around with Text Analysis API
&lt;/h2&gt;

&lt;p&gt;Once you subscribe, you can test the API and check the response this &lt;a href="https://rapidapi.com/gaurmanojkumar530/api/text-analysis12/?utm_source=dev.to%2Frapidapi&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;Text Analysis&lt;/a&gt; API returns. You can test multiple endpoints with different parameters using the API playground. Let’s try to dig in with our current API to integrate it with our application.&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Endpoints &lt;br&gt;
Here, you can take a quick look at the endpoints an interface supports. You can also search for a distinct endpoint.   &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Documentation&lt;br&gt;
Here, you can access and change all the necessary details required to test an endpoint. For example, you can pass values in the different parameters in the documentation section.    &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Code&lt;br&gt;
Every developer wants and loves this section. You can copy-paste the code directly from here. RapidAPI supports 20 programming languages with 40 different libraries.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The &lt;a href="https://rapidapi.com/gaurmanojkumar530/api/text-analysis12/?utm_source=dev.to%2Frapidapi&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;Text Analysis&lt;/a&gt; API has many endpoints. You can play around with each one of them separately. For this particular project, we need the POST &lt;code&gt;sentiment-analysis&lt;/code&gt; endpoint. This endpoint lets us analyze a paragraph of 1000 characters.&lt;/p&gt;

&lt;p&gt;Select the POST &lt;code&gt;sentiment-analysis&lt;/code&gt; endpoint and scroll down a little bit in the documentation section. You will find a request body section, here you can pass the string you want to analyze.&lt;br&gt;
Great, we are all set to hit the “Test Endpoint” button.&lt;/p&gt;

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

&lt;p&gt;After hitting the “Test Endpoint” button, you will see the endpoint (API) result in the third section of API Playground.&lt;/p&gt;

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

&lt;p&gt;In the response body (returned data from the server) you will get an &lt;code&gt;aggregate-sentiment&lt;/code&gt; object which contains all the negative, positive, neutral, and compound values of the string. The response body all contains the sentiment key which tells us the overall &lt;code&gt;sentiment&lt;/code&gt; of the text.&lt;/p&gt;
&lt;h2&gt;
  
  
  Integrate Text Analysis API into Your React Application
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://reactjs.org/"&gt;React&lt;/a&gt; is a front-end JavaScript library for building user interfaces. In this article, you will learn how to integrate an API into your React application and build a text sentiment analysis. Just follow the steps below.&lt;/p&gt;
&lt;h3&gt;
  
  
  1. Create a React Application
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/facebook/create-react-app"&gt;Create React App&lt;/a&gt; is the simplest way to set up a React application by running one command. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx create-react-app sentiment-analysis&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You will need to have &lt;a href="https://nodejs.org/en/"&gt;Node.js&lt;/a&gt;(version &amp;gt;= 6) on your local machine. If you haven’t, just download it for free.&lt;br&gt;
Create-react-app command will create a folder for you with all the necessary files and folders required for a React application. You will get a node_modules, public, and src folder.&lt;/p&gt;

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

&lt;p&gt;We want a form in our application where users can add the test in order to retrieve the sentiment. We just need an input field and a submit button in the form.    &lt;/p&gt;

&lt;p&gt;Go to your project folder (sentiment-analysis that we just created in the first step) and you’ll find that React created a bunch of other folders and files for us. We don’t need to check them all right now.      &lt;/p&gt;

&lt;p&gt;Just Go to the sentiment-analysis folder &amp;gt; src &amp;gt; App.js file and create a form with an URL input field and a submit button.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;form&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
       &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;placeholder&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Enter your text here.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
       &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;btn&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;submit&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Analyze&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
     &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/form&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Run the application to check the output by running the following command from the root of the project and go to &lt;a href="https://localhost:3000"&gt;https://localhost:3000&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm start&lt;/code&gt;&lt;/p&gt;

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

&lt;h3&gt;
  
  
  3. Copy-paste the code snippet from RapidAPI Hub
&lt;/h3&gt;

&lt;p&gt;We are all set to integrate Text Analysis API code into our application. You don’t even need to write the code. RapidAPI provides the code snippet in 20 programming languages with 40 libraries’ support.    &lt;/p&gt;

&lt;p&gt;Go to the [Test Analysis(&lt;a href="https://rapidapi.com/gaurmanojkumar530/api/text-analysis12/?utm_source=dev.to%2Frapidapi&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;https://rapidapi.com/gaurmanojkumar530/api/text-analysis12/?utm_source=dev.to%2Frapidapi&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel&lt;/a&gt;) API homepage and copy the code snippet from the Copy Snippets section of the API playground.    &lt;/p&gt;

&lt;p&gt;Select the JavaScript language and &lt;a href="https://github.com/axios/axios"&gt;axios&lt;/a&gt; method from the dropdown menu and click on the “Copy Code” button.&lt;/p&gt;

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

&lt;p&gt;Create a function &lt;code&gt;fetchData()&lt;/code&gt; in the App.js file and paste the code inside that function.     &lt;/p&gt;

&lt;p&gt;We need to install &lt;code&gt;axios&lt;/code&gt; library first in order to use it in our application. Run the following command from the root of the project.    &lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install axios&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Let the user enter the text and get the sentiment
&lt;/h3&gt;

&lt;p&gt;We are almost done! We just need to validate the form so that the user can enter the text to get the result.   &lt;/p&gt;

&lt;p&gt;Let’s complete the form first. Create two useState hooks in the App.js file, one for handling the state of text that the user enters and the second for loading while API fetching the response from the server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setText&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setIsLoading&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;form&lt;/span&gt;
  &lt;span class="nx"&gt;onSubmit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;setText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;setIsLoading&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}}&lt;/span&gt;
  &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;
    &lt;span class="nx"&gt;onChange&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;setImageLink&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
    &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nx"&gt;placeholder&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Enter your text here…&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;btn&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;submit&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Analyze&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/form&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As simple as that, we are setting the text entered by the user inside the &lt;code&gt;text&lt;/code&gt; variable and calling the &lt;code&gt;fetchData&lt;/code&gt; function on form submit.&lt;/p&gt;

&lt;p&gt;Let’s create another useState hook for storing the response that the server returns.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const [sentiment, setSentiment] = useState(“”);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Modify the &lt;code&gt;fetchData&lt;/code&gt; function a little bit to store the &lt;code&gt;sentiment&lt;/code&gt; response string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;setSentiment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sentiment&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;setIsLoading&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Render the sentiment on the webpage when API successfully returns the data. You can do this by adding some paragraph tags inside the return method in the App.js file.   &lt;/p&gt;

&lt;p&gt;If you missed some parts, this is how the entire App.js file looks like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;axios&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setText&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;sentiment&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setSentiment&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setIsLoading&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://text-analysis12.p.rapidapi.com/sentiment-analysis/api/v1.1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;content-type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;x-rapidapi-host&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text-analysis12.p.rapidapi.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;x-rapidapi-key&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;REACT_APP_API_KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;language&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;english&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="nx"&gt;axios&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;setSentiment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sentiment&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;setIsLoading&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Text&lt;/span&gt; &lt;span class="nx"&gt;Sentiment&lt;/span&gt; &lt;span class="nx"&gt;Analysis&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;form&lt;/span&gt;
        &lt;span class="nx"&gt;onSubmit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
          &lt;span class="nx"&gt;setText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="nx"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;}}&lt;/span&gt;
        &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;
      &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;
          &lt;span class="nx"&gt;onChange&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;setText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
          &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
          &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="nx"&gt;placeholder&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Enter your text here…&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
        &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;btn&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;submit&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Analyze&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/form&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;data&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Loading&lt;/span&gt;&lt;span class="err"&gt;…&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;data&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Sentiment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;span&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;sentiment&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;)}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One important thing to note here is that we have passed the API key as&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"x-rapidapi-key": process.env.REACT_APP_API_KEY,&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;x-rapidapi-key&lt;/code&gt; is your API key that RapidAPI provides using which you can access over 35,000 excellent APIs. It’s always recommended to pass the API key as an environment variable because it’s a confidential thing. Anyone can use your API subscription if they have your API key.&lt;/p&gt;

&lt;p&gt;Create a .env inside the &lt;code&gt;sentiment-analysis&lt;/code&gt; folder and add your API key inside &lt;code&gt;REACT_APP_API_KEY&lt;/code&gt;(you can call it whatever you want but it should start with the prefix &lt;code&gt;REACT_APP_&lt;/code&gt;) variable. Now you can access it inside the App.js file as &lt;code&gt;process.env.REACT_APP_API_KEY&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Output
&lt;/h3&gt;

&lt;p&gt;Yay! Run the &lt;code&gt;npm start&lt;/code&gt; command, and you’ll see the result at &lt;a href="http://localhost:3000/"&gt;http://localhost:3000/&lt;/a&gt;.&lt;/p&gt;

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

&lt;p&gt;You can check the working project &lt;a href="https://codesandbox.io/s/festive-turing-j979h"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Add basic styling to make it more appealing&lt;/p&gt;

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

&lt;p&gt;Go to &lt;a href="https://rapidapi.com/hub/?utm_source=dev.to%2Frapidapi&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;RapidAPI Hub&lt;/a&gt; and create a free account to get your API key. The fun part is that you can use over 35,000 excellent APIs with just one API key. So it’s worth creating a free account on RapidAPI Hub.&lt;/p&gt;

&lt;p&gt;Feel free to drop your suggestions, feedback, and doubts down below. We love checking them out. &lt;br&gt;
With that said, we hope you enjoy this article. Peace out!! Keep coding! We will catch you with the next excellent project idea.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Create an Emotions Recognition App</title>
      <dc:creator>Pratham 👨‍💻✨</dc:creator>
      <pubDate>Fri, 10 Sep 2021 15:49:22 +0000</pubDate>
      <link>https://forem.com/rapidapi/how-to-create-an-emotions-recognition-app-i3f</link>
      <guid>https://forem.com/rapidapi/how-to-create-an-emotions-recognition-app-i3f</guid>
      <description>&lt;p&gt;Emotion recognition is the process of identifying human emotion. Extracting and understanding emotion have high importance in the interaction between human and machine communication. Nowadays, many companies use emotion recognition models in their intelligent systems to improve machine interaction with humans.   &lt;/p&gt;

&lt;p&gt;&lt;a href="https://rapidapi.com/cloud-actions-cloud-actions-default/api/facial-emotion-recognition/?utm_source=dev.to/rapidapi&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;Facial Emotion Recognition&lt;/a&gt; is an excellent API available on &lt;a href="https://rapidapi.com/hub/?utm_source=dev.to/rapidapi&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;RapidAPI Hub&lt;/a&gt;, using which you can create simple yet powerful emotion recognition systems. So today, we will be looking at how to create an Emotion Recognition App using an API.  &lt;/p&gt;

&lt;h3&gt;
  
  
  How to connect to the Facial Emotion Recognition API
&lt;/h3&gt;

&lt;p&gt;RapidAPI handles all the API development things very effectively. You don't need to worry about any complicated stuff related to API. RapidAPI does all the communications by itself. You need to register on RapidAPI Hub if you want to use any API. RapidAPI provides you a single API key using which you can access over 35,000 APIs conveniently.    &lt;/p&gt;

&lt;p&gt;Go to &lt;a href="https://rapidapi.com/hub/?utm_source=dev.to/rapidapi&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;RapidAPI Hub&lt;/a&gt; and create a free account. &lt;/p&gt;

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

&lt;p&gt;The majority of the APIs offer a freemium plan. You don't even need to add credit card details to access them. Let's choose the best-suited &lt;a href="https://rapidapi.com/cloud-actions-cloud-actions-default/api/facial-emotion-recognition/pricing/?utm_source=dev.to/rapidapi&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;pricing plan&lt;/a&gt; for Facial Emotion Recognition.   &lt;/p&gt;

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

&lt;p&gt;The Basic plan of Facial Emotion Recognition is free but keep in mind that it only offers ten API calls per day. You can always change the plan according to your needs. Just click on the "Subscribe" button of the Basic plan.   &lt;/p&gt;

&lt;p&gt;Now we are good to create an Emotion Recognition App using this API.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Play around with Facial Emotion Recognition API
&lt;/h3&gt;

&lt;p&gt;Once you subscribe, you can test the API and check the response this &lt;a href="https://rapidapi.com/cloud-actions-cloud-actions-default/api/facial-emotion-recognition/?utm_source=dev.to/rapidapi&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;Facial Emotion Recognition&lt;/a&gt; API returns. You can test multiple endpoints with different parameters using the API playground. Let's try to dig in with our current API to integrate it with our application.&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FiYTgpp6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e26ri5hk43opyu23zg0w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FiYTgpp6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e26ri5hk43opyu23zg0w.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Endpoint - Here, you can take a quick look at the endpoints an interface supports. You can also search for a distinct endpoint.&lt;/li&gt;
&lt;li&gt;Documentation - Here, you can access and change all the necessary details required to test an endpoint. For example, you can pass values in the different parameters in the documentation section.&lt;/li&gt;
&lt;li&gt;Code - Every developer wants and loves this section. You can copy-paste the code directly from here. RapidAPI supports 20 programming languages with 40 different libraries.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The Facial Emotion Recognition API has only one endpoint, and that's enough for us. It lets us make a POST request using the image address, which gives the emotions in return. We can either pass the URL or base64 as the image string. Let's test this API and see what we get in return.     &lt;/p&gt;

&lt;p&gt;Add the image URL in the source and select the URL for the sourceType parameter.     &lt;/p&gt;

&lt;p&gt;Great, we are all set to hit that "Test Endpoint" button.&lt;/p&gt;

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

&lt;p&gt;After hitting the "Test Endpoint" button, you will see the endpoint (API) result in the third section of API Playground.&lt;/p&gt;

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

&lt;p&gt;You'll get an object with two keys; the first key contains all the emotion values. Whereas the second key contains the Face Annotations.&lt;/p&gt;

&lt;p&gt;We need the emotions key, which contains seven different values. &lt;/p&gt;
&lt;h3&gt;
  
  
  Integrate Facial Emotion Recognition API into Your React Application
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://reactjs.org/"&gt;React&lt;/a&gt; is a front-end JavaScript library for building user interfaces. We will cover everything in detail so If you're not familiar with React, follow the steps below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Create a React Application&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create React App is the simplest way to set up a React application by running one command.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx create-react-app emotion-recognition&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You will need to have &lt;a href="https://nodejs.org/en/"&gt;Node.js&lt;/a&gt; on your local machine. If you haven't, download it for free.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;create-react-app&lt;/code&gt; command will create a folder for you with all the required files for a React application. You will get a node_modules, public, and src folder. You will understand each and everything automatically as you go further in the world of React.   &lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;2. Create a Form&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We want a form in our Emotion Recognition application where users can add the image URL to retrieve the emotions. We need an input field and a submit button in the form.&lt;/p&gt;

&lt;p&gt;Go to your project folder (emotion-recognition that we just created in the first step) and you'll find that React created a bunch of other folders and files for us. We don't need to check them all right now. &lt;code&gt;Go to the emotion-recognition folder &amp;gt; src &amp;gt; App.js&lt;/code&gt;, and create a form with an URL input field and a submit button.&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() {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;form action=""&amp;gt;
        &amp;lt;input type="url" name="url" id="url" placeholder="https://..." /&amp;gt;
        &amp;lt;input className="btn" type="submit" value="Send Request"/
      &amp;lt;/form&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
export default App;

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

&lt;/div&gt;



&lt;p&gt;Run the application to check the output by running the following command from the root of the project:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm start&lt;/code&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;3. Copy-paste the code snippet from RapidAPI Hub&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We are all set to integrate Facial Emotion Recognition API code into our application. You don't even need to write the code. RapidAPI provides the code snippet in 20 programming languages with 40 libraries' support.&lt;/p&gt;

&lt;p&gt;Go to the &lt;a href="https://rapidapi.com/cloud-actions-cloud-actions-default/api/facial-emotion-recognition/?utm_source=dev.to/rapidapi&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;Facial Emotion Recognition&lt;/a&gt; API homepage and copy the code snippet from the third section of the API playground.&lt;/p&gt;

&lt;p&gt;Select the JavaScript language and fetch method from the dropdown menu and click on the "Copy Code" button.&lt;/p&gt;

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

&lt;p&gt;Create a function &lt;code&gt;fetchData()&lt;/code&gt; in the App.js file and paste the code inside that function. Make sure to pass the request body after stringifying it. Learn more about &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify"&gt;JSON.stringify&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;body: JSON.stringify({
  source: "",
  sourceType: "url"
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Let the user enter the image URL and get the emotions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We are almost done! We need to validate the form to enter the URL to get the result.&lt;/p&gt;

&lt;p&gt;Let's complete the form first. Create two useState hooks in the App.js file, one for handling the state of URL that user enters and the second for loading while API fetching the response from 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;Const [imageLink, setImageLink] = useState("");
const [isLoading, setIsLoading] = useState(true);
&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;&amp;lt;form
  onSubmit={(event) =&amp;gt; {
    event.preventDefault();
    fetchData();
    setImageLink("");
    setIsLoading(true);
  }}
  action=""
&amp;gt;
  &amp;lt;input
    onChange={(event) =&amp;gt; setImageLink(event.target.value)}
    type="url"
    name="url"
    id="url"
    value={imageLink}
    className="search-input"
    placeholder="https://..."
  /&amp;gt;
 &amp;lt;input className="btn" type="submit" value="Send Request" /&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As simple as that, we are setting the image URL inside the imageLink variable and calling the &lt;code&gt;fetchData&lt;/code&gt; function on form submit.&lt;/p&gt;

&lt;p&gt;Let's create another &lt;code&gt;useState&lt;/code&gt; hook for storing the response that the server returns.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const [emotions, setEmotions] = useState({});&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Modify the &lt;code&gt;fetchData&lt;/code&gt; function a little bit to store the &lt;code&gt;emotions&lt;/code&gt; response object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.then((response) =&amp;gt; response.json())
.then((data) =&amp;gt; {
  setEmotions(data.emotions[0]);
  setIsLoading(false);
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Render the data(emotions) on the webpage when API successfully returns the data. You can do this by adding some paragraph tags inside the return method in the App.js file.&lt;/p&gt;

&lt;p&gt;If you missed some parts, this is how the entire App.js file looks like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState } from "react";
import ReactDOM from "react-dom";
function App() {
  const [imageLink, setImageLink] = useState("");
  const [emotions, setEmotions] = useState({});
  const [isLoading, setIsLoading] = useState(true);
function fetchData() {
  fetch("https://facial-emotion-recognition.p.rapidapi.com/cloudVision/facialEmotionRecognition",
   {
     method: "POST",
     headers: {
       "content-type": "application/json",
       "x-rapidapi-host": "facial-emotion-recognition.p.rapidapi.com",
       "x-rapidapi-key": process.env.REACT_APP_API_KEY,
     },
     body: JSON.stringify({
       source: imageLink,
       sourceType: "url",
     }),
  }
)
  .then((response) =&amp;gt; response.json())
  .then((data) =&amp;gt; {
    console.log(data);
    setEmotions(data.emotions[0]);
    console.log(emotions);
    setIsLoading(false);
  })
  .catch((err) =&amp;gt; {
    console.error(err);
  });
}
return (
  &amp;lt;div&amp;gt;
    &amp;lt;h1&amp;gt;Emotion Recognition&amp;lt;/h1&amp;gt;
    &amp;lt;form onSubmit={(event) =&amp;gt; {
            event.preventDefault();
            fetchData();
            setImageLink("");
            setIsLoading(true);
          }}
          action=""
     &amp;gt;
       &amp;lt;input onChange={(event) =&amp;gt; setImageLink(event.target.value)}
              type="url"
              name="url"
              id="url"
              value={imageLink}
              className="search-input"
              placeholder="https://..."
        /&amp;gt;
        &amp;lt;input className="btn" type="submit" value="Send Request" /&amp;gt;
      &amp;lt;/form&amp;gt;
      {isLoading ? (
        ""
        ) : (
        &amp;lt;div className="data"&amp;gt;
          &amp;lt;p&amp;gt;Joy: &amp;lt;span&amp;gt;{emotions.joyLikelihood}&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
          &amp;lt;p&amp;gt;Anger: &amp;lt;span&amp;gt;{emotions.angerLikelihood}&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
          &amp;lt;p&amp;gt;Suprise: &amp;lt;span&amp;gt;{emotions.surpriseLikelihood}&amp;lt;/span&amp;lt;/p&amp;gt;
          &amp;lt;p&amp;gt;Sorrow: &amp;lt;span&amp;gt;{emotions.sorrowLikelihood}&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
     )}
    &amp;lt;/div&amp;gt;
  );
}
export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One important thing to note here is that we have passed the API key as&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"x-rapidapi-key": process.env.REACT_APP_API_KEY,&lt;/code&gt;  &lt;/p&gt;

&lt;p&gt;&lt;code&gt;x-rapidapi-key&lt;/code&gt; is your API key that RapidAPI provides using which you can access over 35,000 excellent APIs. It's always recommended to pass the API key as an environment variable because it's confidential. Anyone can use your API subscription if they have your API key.&lt;/p&gt;

&lt;p&gt;Create a .env inside the emotion-recognition folder and add your API key inside REACT_APP_API_KEY(you can call it whatever you want but it should start with the prefix REACTAPP ) variable. Now you can access it inside the App.js file as process.env.REACT_APP_API_KEY.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Output&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yay! Run the npm start command, and you'll see the result at &lt;a href="https://localhost:3000"&gt;https://localhost:3000&lt;/a&gt;.&lt;/p&gt;

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

&lt;p&gt;You can check the working project &lt;a href="https://codesandbox.io/s/emotion-recognition-q9si0"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Go to &lt;a href="https://rapidapi.com/hub/?utm_source=dev.to/rapidapi&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;RapidAPI Hub&lt;/a&gt; and create a free account to get your API key. The fun part is that you can use over 35,000 excellent APIs with just one API key. So it's worth creating a free account on RapidAPI Hub.&lt;/p&gt;

&lt;p&gt;Feel free to drop your suggestions, feedback, and doubts down below. We love reading them out.&lt;/p&gt;

&lt;p&gt;With that said, we hope you enjoy this article. Peace out!! Keep coding! We will catch you with the next excellent project idea.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Introduction to SOAP API</title>
      <dc:creator>Pratham 👨‍💻✨</dc:creator>
      <pubDate>Fri, 03 Sep 2021 19:15:25 +0000</pubDate>
      <link>https://forem.com/rapidapi/introduction-to-soap-api-27p2</link>
      <guid>https://forem.com/rapidapi/introduction-to-soap-api-27p2</guid>
      <description>&lt;p&gt;SOAP is a necessary protocol that helped introduce the widespread use of APIs.   &lt;/p&gt;

&lt;p&gt;SOAP is the acronym for Simple Object Access Protocol. It is a standardized protocol that relies on XML to make requests and receive responses. Even though SOAP is based on XML, the SOAP protocol is still in wide usage.   &lt;/p&gt;

&lt;p&gt;SOAP APIs make data available as a service and are typically used when performing transactions involving multiple API calls or applications where security is the primary consideration.     &lt;/p&gt;

&lt;p&gt;SOAP was initially developed for Microsoft in 1998 to provide a standard mechanism for integrating services on the internet regardless of the operating system, object model, or programming language.&lt;/p&gt;

&lt;h3&gt;
  
  
  How SOAP APIs work
&lt;/h3&gt;

&lt;p&gt;The “S” in SOAP stands for Simple, and for a good reason — SOAP can be used with less complexity as it requires less coding in the app layer for transactions, security, and other functions.   &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Primary characteristics of SOAP&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Extensibility&lt;br&gt;
SOAP allows for extensions that introduce more robust features, such as Windows Server Security, Addressing, and more.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Neutrality&lt;br&gt;
SOAP is capable of operating over a wide range of protocols, like UDP, JMS, SMTP, TCP, and HTTP.can operate.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Independence&lt;br&gt;
SOAP API responses are purely based on XML. Therefore SOAP APIs are platform and language independent.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  When to Use SOAP APIs
&lt;/h3&gt;

&lt;p&gt;Developers continue to debate the pros and cons of using SOAP and REST. The best one for your project will be the one that aligns with your needs.     &lt;/p&gt;

&lt;p&gt;SOAP APIs remain a top choice for corporate entities and government organizations that prioritize security, even though REST has largely dominated web applications. It is more secure than REST as it uses WS-Security for transmission along with a Secure Socket Layer.SOAP also has more excellent transactional reliability, which is another reason why SOAP historically has been favored by the banking industry and other large entities. &lt;/p&gt;

&lt;h3&gt;
  
  
  Difference between SOAP and REST APIs
&lt;/h3&gt;

&lt;p&gt;SOAP is more secure than REST as it uses &lt;a href="https://www.ibm.com/docs/en/app-connect/11.0.0?topic=security-ws"&gt;WS-Security&lt;/a&gt; for transmission along with a Secure Socket Layer. SOAP is stateful as it takes the entire request as a whole. REST involves multiple methods while dealing with requests and responses.   &lt;/p&gt;

&lt;p&gt;Head over to &lt;a href="https://rapidapi.com/hub?utm_source=dev.to%2Frapidapi&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;RapidAPI Hub&lt;/a&gt; and explore tens of thousands of SOAP APIs you can use with a single API Key.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Introduction to  REST API</title>
      <dc:creator>Pratham 👨‍💻✨</dc:creator>
      <pubDate>Fri, 27 Aug 2021 16:16:26 +0000</pubDate>
      <link>https://forem.com/rapidapi/introduction-to-rest-api-1a9h</link>
      <guid>https://forem.com/rapidapi/introduction-to-rest-api-1a9h</guid>
      <description>&lt;p&gt;The abbreviation REST stands for &lt;strong&gt;"REpresentational State Transfer"&lt;/strong&gt;.    &lt;/p&gt;

&lt;p&gt;REST APIs are used to call resources and allow the software to communicate based on standardized principles, properties, and constraints.    &lt;/p&gt;

&lt;h3&gt;
  
  
  How REST APIs work
&lt;/h3&gt;

&lt;p&gt;REST APIs operate on a simple request/response system. You can send a request using these HTTP methods:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GET&lt;/li&gt;
&lt;li&gt;POST&lt;/li&gt;
&lt;li&gt;PUT&lt;/li&gt;
&lt;li&gt;PATCH&lt;/li&gt;
&lt;li&gt;DELETE &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;REST APIs can include endpoints, headers, URL parameters, and the request body. The endpoints perform a specific action on the URL, take some optional parameters and might return the data. Think of it like an automated answering machine that asks you to press 1 for service, press 2 for another service, 3 for yet another service, and so on. When you send a request to an endpoint, it responds with the relevant data, which is generally formatted as JSON, XML, plain text, images, HTML, and more.    &lt;/p&gt;

&lt;p&gt;REST APIs can also be designed with many different endpoints that return different types of data. Accessing multiple REST API endpoints require multiple API calls.   &lt;/p&gt;

&lt;p&gt;A true RESTful API will also conform to the REST architectural constraints outlined by Fielding's dissertation, including:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Client-Server Architecture&lt;br&gt;
The client and server are decoupled to improve scalability and allow the components to evolve independently.   &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Statelessness&lt;br&gt;
Statelessness means that every HTTP request happens in complete isolation. Each request contains the information necessary to service the request. The server never relies on information from previous requests. There's no state.   &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cacheability&lt;br&gt;
Responses can be explicitly or implicitly defined as cacheable or non-cacheable to improve scalability and performance. For example, enabling the cache of GET requests can improve the response times of requests for resource data.     &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Layering&lt;br&gt;
Different layers of the API architecture should work together, creating a scalable system that is easy to update or adjust.     &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Uniform Interface&lt;br&gt;
Communication between the client and the server must be done in a standardized language that is independent of both. This improves scalability and flexibility.     &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  When to Use REST APIs
&lt;/h3&gt;

&lt;p&gt;As you can see from the constraints of the REST architectural style, REST APIs are a good fit for projects that need to be&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Flexible&lt;/li&gt;
&lt;li&gt;Scalable&lt;/li&gt;
&lt;li&gt;Fast&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;REST APIs are particularly well-suited for web applications. In addition, if you are looking for the following characteristics, REST is a strong option:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Familiarity&lt;br&gt;
Most people in your engineering team have already interacted with  a REST API. This type of API, being the most common, has the shortest learning curve.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Interoperability&lt;br&gt;
Due to the popularity of REST, many platforms and frameworks have a built-in library capable of interfacing with a REST API that has wide support.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Development efficiency&lt;br&gt;
REST APIs are reusable, enabling developers to easily create independent microservices that work independently of one another as they are decoupled from clients and accessible by multiple applications.    &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;REST APIs have become the most popular type of API due to their flexible and fast performance. We anticipate REST APIs will continue to be a popular choice for years to come. With that being said, this is pretty much it for this article.&lt;/p&gt;

&lt;p&gt;Head over to &lt;a href="https://RapidAPI.com?utm_source=dev.to/rapidapi&amp;amp;utm_medium=DevRel&amp;amp;utm_campaign=DevRel"&gt;RapidAPI Hub&lt;/a&gt; and explore tens of thousands of REST APIs you can use with a single API Key.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Introduction to APIs</title>
      <dc:creator>Pratham 👨‍💻✨</dc:creator>
      <pubDate>Fri, 20 Aug 2021 17:11:37 +0000</pubDate>
      <link>https://forem.com/rapidapi/introduction-to-apis-bie</link>
      <guid>https://forem.com/rapidapi/introduction-to-apis-bie</guid>
      <description>&lt;p&gt;API is the acronym for &lt;strong&gt;Application Programming Interface.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;API is a set of definitions and protocols that allow technology products and services to communicate with each other via the internet. APIs are how apps talk to each other.&lt;/p&gt;

&lt;p&gt;Don't worry if that sounds confuses you. Let's use a simple analogy to try to understand what an API is.&lt;/p&gt;

&lt;p&gt;Imagine you are building an app like Uber, and when a user signs up, you want to check if their email is valid.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;How would you do that?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;There's pretty complicated logic that goes into validating an email address:    &lt;/p&gt;

&lt;p&gt;You'd check the format of string (does it have an @ sign?), you would ping the domain to make sure it runs an email server, and check a couple of blocklists to make sure it's not a delisted address.     &lt;/p&gt;

&lt;p&gt;Do you think you have time to build and maintain an email validation service like that? Especially when it's just you or with a small team. Wouldn't you rather spend time improving your business than spending time on trivial things like this?     &lt;/p&gt;

&lt;p&gt;Instead, you could use an API - a 3rd party service that already implements the email validation logic, maintains it and improves it as it's their business to do so. You can rely on a 3rd party API to validate your users' email IDs.&lt;/p&gt;

&lt;h4&gt;
  
  
  📌 Hence we can say that APIs help developers in 4 key ways: &lt;br&gt;&lt;br&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1. APIs increase the development speed 🚝&lt;/strong&gt; &lt;br&gt;
By leveraging APIs — developers spend less time implementing trivial features and get more time to focus on their essential business. Execution speed matters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. APIs reduce the overall software cost 💸&lt;/strong&gt;&lt;br&gt;
When you need to implement and maintain less code (relying on APIs), your development cost goes down. It’s a classic Build vs Buy argument.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. APIs can increase the quality of the software ⭐&lt;/strong&gt;&lt;br&gt;
Using a good API can make your software better. Each API component is developed by a business primarily focused on making it the best possible solution rather than one team that has to be good at many things.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. APIs yield new possibilities 🌅&lt;/strong&gt;&lt;br&gt;
With APIs, developers can now integrate with data sets and implement features like AI and Machine Learning that they wouldn't have been able to use before, creating new business opportunities.&lt;/p&gt;

&lt;p&gt;And that's pretty much about it for this article.&lt;/p&gt;

&lt;p&gt;We hope you liked this article. If you have any doubts, feel free to add a comment below.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
