create account

How to use Google sheet as a REST API by tykee

View this thread on: hive.blogpeakd.comecency.com
· @tykee ·
$4.77
How to use Google sheet as a REST API
![restapi.png](https://images.hive.blog/DQmeyFojBPBYcxg1mQfVG9jtvpps7oUX6ATCjk44zWUinuU/restapi.png)


There are times when you just want a small database to store data and you do not want to create any serious database like Mongo. There are services that help to store form data, but some of them are custom-made and don't look professional. 

So in this post, I will discuss how to use Google Sheets to store data in real-time. 

Without further ado, let's start.

First, go to: https://docs.google.com/spreadsheets/ and create a blank page. 

Name the page on whatever you want to save in it. For me, I am using "Players" and add the title of the data you want to collect from your users. I have Name, Rank and Stage in mine

![](https://i.imgur.com/1LBgqqi.png)

Click on the share, and change the restriction to "anyone with the link" and change viewer to "editor". Then copy the link. 

Visit sheet.best, sign up with your gmail and click "Connection". Give your connection a name(same as it is on the Google sheet) then paste the link copied from google sheet in the "Connection URL", and click connect. This will create another DB for you in the sheet.best.

### WHY SHEET.BEST
If you try to post directly through a script generated on google Sheets, you may encounter Cross-origin resource sharing issues, This is one of the things sheet.best handles for you

![Screen Shot 20230321 at 9.47.10 PM.png](https://images.hive.blog/DQmNRCuibcDjST55aKRn5FFJth9QJVYiA2CcuZaQqPquvwG/Screen%20Shot%202023-03-21%20at%209.47.10%20PM.png)

Click "details" and copy the "connection URL" generated on sheet.best


_Note: I am using a free plan of the sheet.best so I can only use 1 Db and I am currently using it for a project._

NEXT...

create react app

```npx create-react-app my-app```
 
and install axios because we will use the post method to save to the sheet. 

```npm install axios```

IN YOUR JSX

```import axios from 'axios';
import React, {useState} from 'react';

const Players = () => {
    const [name, setName] = useState('')
    const [rank, setRank] = useState('')
    const [stage, setStage] = useState('')
    const handleSubmit =(e) => {
         e.preventDefault();    
        const data = {
            Name: name,
            Rank: rank,
            Stage: stage
        }
        axios.post('https:use-the-link-copied-from-sheet.best-here', data).then((response)=> {

            // clear field
            setName('');
            setRank('');
            setStage('');
        })
    }
    return(
        <div className='form-container'>
            <form className='form' action="" onSubmit={handleSubmit}>
                <input type="text" name="Name" id="" placeholder='Name' required onChange={(e)=>setName(e.target.value)} value={name}/>
                <input type="text" name="Rank" id="" placeholder='Rank' required onChange={(e)=>setRank(e.target.value)} value={rank}/>
                <input type="text" name="Stage" id="" placeholder='Stage' required onChange={(e)=>setStage(e.target.value)} value={stage}/>
                <input type="submit" value="submit" />
            </form>
        </div>
    )
}
export default Players;

 ```



This works in real-time. You can copy this code and adjust to whatever you want.  

Thanks for your time. 

Posted using [Proof of Brain](https://www.proofofbrain.io/@tykee/how-to-use-google-sheet-as-a-rest-api)
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 188 others
properties (23)
authortykee
permlinkhow-to-use-google-sheet-as-a-rest-api
categoryhive-150329
json_metadata{"tags":["hive-150329","proofofbrain","tutorial","cent","ctp","neoxian","vyb","programming","stem"],"image":["https://images.hive.blog/DQmeyFojBPBYcxg1mQfVG9jtvpps7oUX6ATCjk44zWUinuU/restapi.png","https://i.imgur.com/1LBgqqi.png","https://images.hive.blog/DQmNRCuibcDjST55aKRn5FFJth9QJVYiA2CcuZaQqPquvwG/Screen%20Shot%202023-03-21%20at%209.47.10%20PM.png"],"links":["https://docs.google.com/spreadsheets/"],"format":"markdown","canonical_url":"https://www.proofofbrain.io/@tykee/how-to-use-google-sheet-as-a-rest-api","app":"proofofbrain/1.1.0"}
created2023-03-22 11:10:33
last_update2023-03-22 11:10:33
depth0
children1
last_payout2023-03-29 11:10:33
cashout_time1969-12-31 23:59:59
total_payout_value2.408 HBD
curator_payout_value2.363 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,388
author_reputation232,935,449,922,164
root_title"How to use Google sheet as a REST API"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id121,857,589
net_rshares9,334,144,226,176
author_curate_reward""
vote details (252)
@stemsocial ·
re-tykee-how-to-use-google-sheet-as-a-rest-api-20230323t050755303z
<div class='text-justify'> <div class='pull-left'>
 <img src='https://stem.openhive.network/images/stemsocialsupport7.png'> </div>

Thanks for your contribution to the <a href='/trending/hive-196387'>STEMsocial community</a>. Feel free to join us on <a href='https://discord.gg/9c7pKVD'>discord</a> to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support.&nbsp;<br />&nbsp;<br />
</div>
properties (22)
authorstemsocial
permlinkre-tykee-how-to-use-google-sheet-as-a-rest-api-20230323t050755303z
categoryhive-150329
json_metadata{"app":"STEMsocial"}
created2023-03-23 05:07:54
last_update2023-03-23 05:07:54
depth1
children0
last_payout2023-03-30 05:07:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length565
author_reputation22,460,214,241,099
root_title"How to use Google sheet as a REST API"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id121,884,516
net_rshares0