{"id":103469,"date":"2020-04-03T07:00:00","date_gmt":"2020-04-03T04:00:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=103469"},"modified":"2022-11-04T10:36:55","modified_gmt":"2022-11-04T08:36:55","slug":"reactjs-api-calls-example","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/reactjs-api-calls-example.html","title":{"rendered":"ReactJS API Calls Example"},"content":{"rendered":"<p>In this article, we will take a look at making API Calls in a ReactJS application. Making API Calls to perform CRUD operations on data is a critical and important feature of most applications. We gain an understanding and learn the intricacies of achieving the same in with ReactJS. ReactJS has soared in popularity and has become the go-to library for Front end Development. <\/p>\n<p>So without further ado let us get started and build an example ReactJS application.<\/p>\n<p>I have used the following toolset and technologies to build the example in this article.<\/p>\n<h2 class=\"wp-block-heading\">1. Tools and Technologies<\/h2>\n<ul class=\"wp-block-list\">\n<li><a rel=\"noreferrer noopener\" aria-label=\"create-react-app  (opens in a new tab)\" href=\"https:\/\/www.npmjs.com\/package\/create-react-app\" target=\"_blank\">create-react-app <\/a><\/li>\n<li><a rel=\"noreferrer noopener\" aria-label=\"ReactJS (opens in a new tab)\" href=\"https:\/\/reactjs.org\/\" target=\"_blank\">ReactJS<\/a><\/li>\n<li><a rel=\"noreferrer noopener\" aria-label=\"NodeJS (opens in a new tab)\" href=\"https:\/\/nodejs.org\/en\/\" target=\"_blank\">NodeJS<\/a><\/li>\n<li><a rel=\"noreferrer noopener\" aria-label=\"Express  (opens in a new tab)\" href=\"https:\/\/www.npmjs.com\/package\/express\" target=\"_blank\">Express <\/a><\/li>\n<li><a rel=\"noreferrer noopener\" aria-label=\"Visual Studio Code IDE (opens in a new tab)\" href=\"https:\/\/code.visualstudio.com\/\" target=\"_blank\">Visual Studio Code IDE<\/a><\/li>\n<li><a href=\"https:\/\/www.npmjs.com\/package\/concurrently\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"concurrently (opens in a new tab)\">concurrently<\/a><\/li>\n<\/ul>\n<p>create-react-app npm package from the folks at Facebook allows us to quickly generate a ReactJS application. We use it here to scaffold a starting point for our example. The latest ReactJS version is pulled down and used by create-react-app. ReactJS is a front end library and we use it here to show how to make API calls in a ReactJS application.<\/p>\n<p>I have used Express to create a rudimentary API for the purposes of our example in Nodejs. concurrently allows us to run multiple commands concurrently like our server API and client-side code here. Visual Studio Code IDE is my editor of choice for front end development although you are free to follow along in an editor of your choice.<\/p>\n<h2 class=\"wp-block-heading\">2. Project Structure<\/h2>\n<p>To generate our project we run the below command:<\/p>\n<pre class=\"brush: bash;\">&gt;npx create-react-app my-app\n<\/pre>\n<p>The npx command downloads a temporary copy of a package and runs it with the parameters provided. And once the above command completes running we should have the following project structure ready.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"302\" height=\"351\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/04\/Project-Structure-API-Calls.jpg\" alt=\"ReactJS API Calls - Project Structure\" class=\"wp-image-103537\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/04\/Project-Structure-API-Calls.jpg 302w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/04\/Project-Structure-API-Calls-258x300.jpg 258w\" sizes=\"(max-width: 302px) 100vw, 302px\" \/><figcaption>Project Structure<\/figcaption><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\">3. Server-side API<\/h2>\n<p>We will create a rudimentary API for use in our example. The API is backed by a sample dataset on which we will perform CRUD operations. The dataset represents a Cricket team of my favorite players. We will edit this list including add\/remove players and update player names calling the server-side API each time. The changes will not be persistent as we will not use a backing database store for the sake of keeping things simple. Our dataset looks like below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>dataset.json<\/em><\/span><\/p>\n<pre class=\"brush: js;\">[\n    {\n        \"name\": \"Sachin Tendulkar\"\n    },\n    {\n        \"name\": \"Gautam Gambhir\"\n    },\n    {\n        \"name\": \"Sourav Ganguly\"\n    },\n    {\n        \"name\": \"Anil Kumble\"\n    },\n    {\n        \"name\": \"Virendar Sehwag\"\n    },\n    {\n        \"name\": \"Jasprit Bumrah\"\n    },\n    {\n        \"name\": \"Viraat Kohli\"\n    },\n    {\n        \"name\": \"Ravindra Jadeja\"\n    },\n    {\n        \"name\": \"Javagal Shreenath\"\n    },\n    {\n        \"name\": \"Kuldeep Yadav\"\n    },\n    {\n        \"name\": \"Rahul Dravid\"\n    },\n    {\n        \"name\": \"Venkatesh Prasad\"\n    }\n]\n<\/pre>\n<p>To realize the Server-side API I have used Express and the code for the Server-side looks like below:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><span style=\"text-decoration: underline\"><em>index.js<\/em><\/span><\/p>\n<pre class=\"brush: js;\">const express = require('express');\nconst app = express();\nconst bodyParser = require(\"body-parser\");\nconst api = require('.\/teamController');\nconst cors = require('cors');\n\napp.use(bodyParser.json());\napp.use(bodyParser.urlencoded({ extended: true }));\napp.use(cors());\napp.use('\/api', api());\n\nconst Port = process.env.PORT || 2019;\n\napp.listen(Port, () =&gt; {\n    console.log(`Listening on ${Port}.`);\n});\n<\/pre>\n<p>The code for the team controller which handles the API request looks like below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>teamController.js<\/em><\/span><\/p>\n<pre class=\"brush: js;\">const router = require('express').Router();\nlet dataset = require('..\/dataset\/dataset.js');\nmodule.exports = () =&gt; {\n    router.get('\/', (req, res) =&gt; {\n        return res.json(dataset);\n    });\n\n    router.post('\/addPlayer', (req, res) =&gt; {\n        dataset.push(req.body);\n        return res.json({ success: \"success\" });\n    });\n\n    router.patch('\/updatePlayer\/:oldName\/:newName', (req, res) =&gt; {\n        let player = dataset.map(p =&gt; p.name.toLowerCase() ===\n req.params.oldName.toLowerCase());\n        player.name = req.params.newName;\n        return res.json({ success: \"success\" });\n    });\n\n    router.delete('\/deletePlayer\/:name', (req, res) =&gt; {\n        dataset = dataset.filter(p =&gt; p.name.toLowerCase() !==\n req.params.name.toLowerCase());\n        return res.json({ success: \"success\" });\n    });\n\n    return router;\n};\n\n<\/pre>\n<p>Now let&#8217;s move on to our client-side application and to making the actual calls to this API.<\/p>\n<h2 class=\"wp-block-heading\">4. Client-side API Calls<\/h2>\n<p>Going about client-side development, I have created three ReactJS components namely, TeamPage, PlayerList, and Player. The TeamPage component hosts our UI. Whereas the PlayerList renders an unordered list of Players from our team. Each player is further passed onto an instance of the Player component to be displayed. Furthermore, the API calls are made from the TeamPage Component with the other two components acting as dumb or not so smart ones.<\/p>\n<p>To make the actual API calls we use the fetch browser API. The code for each of the components discussed above looks like below.<\/p>\n<p><span style=\"text-decoration: underline\"><em>TeamPage.js<\/em><\/span><\/p>\n<pre class=\"brush: js;\">import React, { useState, useEffect } from 'react';\nimport PlayerList from '.\/PlayerList';\nimport dataService from '..\/Services\/DataService';\n\nfunction TeamPage(props) {\n    const [team, setTeam] = useState();\n    useEffect(() =&gt; {\n        dataService.getTeam()\n            .then(resp =&gt; setTeam(resp))\n            .catch(err =&gt; console.log(err));\n    }, []);\n    const deletePlayer = (name) =&gt; {\n        dataService.deletePlayer(name)\n            .then(r =&gt; {\n                dataService.getTeam()\n                    .then(resp =&gt; setTeam(resp))\n                    .catch(err =&gt; console.log(err));\n            })\n            .catch(err =&gt; console.log(err));\n    }\n    const updatePlayer = (oldname, newname) =&gt; {\n        dataService.updatePlayer(oldname, newname)\n            .then(r =&gt; {\n                dataService.getTeam()\n                    .then(resp =&gt; setTeam(resp))\n                    .catch(err =&gt; console.log(err));\n            })\n            .catch(err =&gt; console.log(err));\n    }\n    return &lt;div style={{\n        display: 'flex',\n        flexDirection: 'column',\n        height: '100vh',\n        width: '100vw',\n        justifyContent: 'center',\n        alignItems: 'center'\n    }}&gt;\n\n        &lt;PlayerList team={team} updatePlayer={updatePlayer}\ndeletePlayer={deletePlayer} addPlayer={addPlayer} \/&gt;\n    &lt;\/div&gt;\n}\n\nexport default TeamPage;\n\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>PlayerList.js<\/em><\/span><\/p>\n<pre class=\"brush: js;\">import React, { useState } from 'react';\nimport Player from '.\/Player';\n\nfunction PlayerList(props) {\n    const [newPlayer, setNewPlayer] = useState(\"\");\n    const handleChange = ({ target }) =&gt; {\n        setNewPlayer(target.value);\n    }\n    const handleClick = () =&gt; {\n        if (!newPlayer) return;\n        props.addPlayer(newPlayer);\n    }\n    return &lt;&gt;\n        &lt;input type=\"text\" value={newPlayer}\n onChange={handleChange} \/&gt;&lt;button \nonClick={handleClick}&gt;+&lt;\/button&gt;\n        &lt;ul&gt;\n            {props.team &amp;&amp; props.team.map(p =&gt; &lt;Player\n                updatePlayer={props.updatePlayer}\n                deletePlayer={props.deletePlayer}\n                key={p.name} player={p} \/&gt;)}\n        &lt;\/ul&gt;&lt;\/&gt;\n}\n\nexport default PlayerList;\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>Player.js<\/em><\/span><\/p>\n<pre class=\"brush: js;\">import React, { useState } from 'react';\n\nfunction Player(props) {\n    const [editMode, setEditMode] = useState(false);\n    const [playerName, setPlayerName] = \n                                     useState(props.player.name);\n    const handleChange = ({ target }) =&gt; {\n        setPlayerName(target.value);\n    }\n    const saveChanges = ({ target }) =&gt; {\n        props.updatePlayer(props.player.name, playerName);\n        setEditMode(false);\n    }\n    const deletePlayer = () =&gt; {\n        props.deletePlayer(playerName);\n    }\n    return &lt;&gt;\n        {!editMode &amp;&amp; &lt;li&gt;{playerName}&lt;\/li&gt;}\n        {editMode &amp;&amp; &lt;&gt;&lt;input value={playerName} onChange=\n{handleChange} \/&gt;&lt;br \/&gt;&lt;\/&gt;}\n        {!editMode &amp;&amp; &lt;&gt;&lt;button onClick={() =&gt; \n{ setEditMode(true) }}&gt;Edit&lt;\/button&gt;&lt;button onClick=\n{deletePlayer}&gt;X&lt;\/button&gt;&lt;\/&gt;}\n        {editMode &amp;&amp; &lt;button onClick={saveChanges}&gt;Save&lt;\/button&gt;}\n    &lt;\/&gt;;\n}\n\nexport default Player;\n<\/pre>\n<p>The code for the dataService looks like below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>DataService.js<\/em><\/span><\/p>\n<pre class=\"brush: js;\">function getTeam() {\n    return window.fetch('\/api')\n        .then(r =&gt; r.json());\n}\n\nfunction addPlayer(player) {\n    return window.fetch('\/api\/addPlayer', {\n        method: 'POST',\n        headers: {\n            'Content-Type': 'application\/json'\n        },\n        body: JSON.stringify(player)\n    })\n        .then(r =&gt; r.json());\n}\n\nfunction updatePlayer(oldname, newname) {\n    return window.fetch(`\/api\/updatePlayer\/${oldname}\/${newname}`\n, \n{\n        method: 'PATCH'\n    })\n        .then(r =&gt; r.json());\n}\n\nfunction deletePlayer(name) {\n    return window.fetch(`\/api\/deletePlayer\/${name}`, {\n        method: 'DELETE'\n    })\n        .then(r =&gt; r.json());\n}\n\nexport default {\n    getTeam,\n    updatePlayer,\n    addPlayer,\n    deletePlayer\n}\n<\/pre>\n<p>Now let us see our application in action.<\/p>\n<h2 class=\"wp-block-heading\">5. Running the application<\/h2>\n<p>To run our application we need to run the following command<\/p>\n<pre class=\"brush: bash;\">\/my-app&gt;npm start\n<\/pre>\n<p>This command as it is setup will launch both, our Server-side API as well as the ReactJS application using concurrently. The result should be as below:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"697\" height=\"689\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/04\/ReactJS-API-Calls-Output.jpg\" alt=\"ReactJS API Calls - Project Output\" class=\"wp-image-103565\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/04\/ReactJS-API-Calls-Output.jpg 697w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/04\/ReactJS-API-Calls-Output-300x297.jpg 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/04\/ReactJS-API-Calls-Output-70x70.jpg 70w\" sizes=\"(max-width: 697px) 100vw, 697px\" \/><figcaption>Project Output<\/figcaption><\/figure>\n<\/div>\n<p>This wraps up our look at API Calls example in a ReactJS Application.<\/p>\n<h2 class=\"wp-block-heading\">6. Download the Source Code<\/h2>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/04\/JCG-ReactJS-API-Calls-Example.zip\"><strong>ReactJS API Calls Example<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will take a look at making API Calls in a ReactJS application. Making API Calls to perform CRUD operations on data is a critical and important feature of most applications. We gain an understanding and learn the intricacies of achieving the same in with ReactJS. ReactJS has soared in popularity and &hellip;<\/p>\n","protected":false},"author":82952,"featured_media":92051,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1903],"tags":[1919],"class_list":["post-103469","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-react-js","tag-reactjs"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>ReactJS API Calls Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this article, we will take a look at making API Calls in a ReactJS application. Making API Calls to perform CRUD operations on data is a critical and\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/reactjs-api-calls-example.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ReactJS API Calls Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this article, we will take a look at making API Calls in a ReactJS application. Making API Calls to perform CRUD operations on data is a critical and\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/reactjs-api-calls-example.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2020-04-03T04:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-04T08:36:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Siddharth Seth\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Siddharth Seth\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-api-calls-example.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-api-calls-example.html\"},\"author\":{\"name\":\"Siddharth Seth\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/09c54717e2cc7956aa8a2df61330f18c\"},\"headline\":\"ReactJS API Calls Example\",\"datePublished\":\"2020-04-03T04:00:00+00:00\",\"dateModified\":\"2022-11-04T08:36:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-api-calls-example.html\"},\"wordCount\":611,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-api-calls-example.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/react-logo.jpg\",\"keywords\":[\"Reactjs\"],\"articleSection\":[\"React.js\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-api-calls-example.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-api-calls-example.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-api-calls-example.html\",\"name\":\"ReactJS API Calls Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-api-calls-example.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-api-calls-example.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/react-logo.jpg\",\"datePublished\":\"2020-04-03T04:00:00+00:00\",\"dateModified\":\"2022-11-04T08:36:55+00:00\",\"description\":\"In this article, we will take a look at making API Calls in a ReactJS application. Making API Calls to perform CRUD operations on data is a critical and\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-api-calls-example.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-api-calls-example.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-api-calls-example.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/react-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/react-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-api-calls-example.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Web Development\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"JavaScript\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\\\/javascript\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"React.js\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\\\/javascript\\\/react-js\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"ReactJS API Calls Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/09c54717e2cc7956aa8a2df61330f18c\",\"name\":\"Siddharth Seth\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g\",\"caption\":\"Siddharth Seth\"},\"description\":\"Siddharth is a Software Development Professional with a Master degree in Computer Applications from IGNOU. He has over 14 years of experience. And currently focused on Software Architecture, Cloud Computing, JavaScript Frameworks for Client and Server, Business Intelligence.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/siddharth-seth-240180\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/siddharth_seth1980\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"ReactJS API Calls Example - Java Code Geeks","description":"In this article, we will take a look at making API Calls in a ReactJS application. Making API Calls to perform CRUD operations on data is a critical and","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/reactjs-api-calls-example.html","og_locale":"en_US","og_type":"article","og_title":"ReactJS API Calls Example - Java Code Geeks","og_description":"In this article, we will take a look at making API Calls in a ReactJS application. Making API Calls to perform CRUD operations on data is a critical and","og_url":"https:\/\/www.javacodegeeks.com\/reactjs-api-calls-example.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2020-04-03T04:00:00+00:00","article_modified_time":"2022-11-04T08:36:55+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg","type":"image\/jpeg"}],"author":"Siddharth Seth","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Siddharth Seth","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/reactjs-api-calls-example.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-api-calls-example.html"},"author":{"name":"Siddharth Seth","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/09c54717e2cc7956aa8a2df61330f18c"},"headline":"ReactJS API Calls Example","datePublished":"2020-04-03T04:00:00+00:00","dateModified":"2022-11-04T08:36:55+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-api-calls-example.html"},"wordCount":611,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-api-calls-example.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg","keywords":["Reactjs"],"articleSection":["React.js"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/reactjs-api-calls-example.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/reactjs-api-calls-example.html","url":"https:\/\/www.javacodegeeks.com\/reactjs-api-calls-example.html","name":"ReactJS API Calls Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-api-calls-example.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-api-calls-example.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg","datePublished":"2020-04-03T04:00:00+00:00","dateModified":"2022-11-04T08:36:55+00:00","description":"In this article, we will take a look at making API Calls in a ReactJS application. Making API Calls to perform CRUD operations on data is a critical and","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-api-calls-example.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/reactjs-api-calls-example.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/reactjs-api-calls-example.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/reactjs-api-calls-example.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Web Development","item":"https:\/\/www.javacodegeeks.com\/category\/web-development"},{"@type":"ListItem","position":3,"name":"JavaScript","item":"https:\/\/www.javacodegeeks.com\/category\/web-development\/javascript"},{"@type":"ListItem","position":4,"name":"React.js","item":"https:\/\/www.javacodegeeks.com\/category\/web-development\/javascript\/react-js"},{"@type":"ListItem","position":5,"name":"ReactJS API Calls Example"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/09c54717e2cc7956aa8a2df61330f18c","name":"Siddharth Seth","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g","caption":"Siddharth Seth"},"description":"Siddharth is a Software Development Professional with a Master degree in Computer Applications from IGNOU. He has over 14 years of experience. And currently focused on Software Architecture, Cloud Computing, JavaScript Frameworks for Client and Server, Business Intelligence.","sameAs":["https:\/\/www.linkedin.com\/in\/siddharth-seth-240180\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/siddharth_seth1980"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/103469","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/82952"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=103469"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/103469\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/92051"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=103469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=103469"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=103469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}