I am trying to use a very simple method to post requests to firebase realtime DB from my reactjs app.
Here is a screenshot of a one entry into my DB . Here the first entry under blogs is the UID of the user and that user can create multiple blogs for example with id b1 in the screenshot.
Here is my code for the POST request:
const id = localStorage.getItem('uid')
const postData = async () => {
var num = localStorage.getItem('blogNumber')
const resp = await fetch(
'https://assignment-c3557-default-rtdb.asia-southeast1.firebasedatabase.app.firebaseio.com/blogs.json',
{
method: 'POST',
body: {
id: {
num : {
title: titleRef.current.value,
description: contentRef.current.value,
createdAt: new Date(),
isPosted: false
}
}
},
headers: {
'Content-Type': 'application/json'
}
});
const data = await resp.json()
localStorage.setItem('blogNumber', localStorage.getItem('blogNumber') +1)
}
I get 400 bad request when trying to hit this url
But according to this page, this seems to be the correct url I am hitting
https://retool.com/blog/your-guide-to-crud-in-firebase-realtimedb-with-rest-api/