- Core API's
- >
- Comments API
- >
- Comments - Create
Comments - Create API
Create a new Comment.
Method POST
Body
{
"name": "John Doe",
"email": "johndoe@example.com",
"body": "This is a sample comment body.",
"post_id": 1
}
How to Use
fetch('https://simplecrudapi.com/api/comments', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
'post_id': 1,
'content': 'This is a beautifully crafted comment, expressing a thoughtful and engaging response to the post. It highlights key points and adds valuable insight to the conversation.'
})
})
.then(response => response.json())
.then(json => console.log(json))
.catch(error => console.error('Error posting data:', error));
Response
{
"data": {
"id": 1,
"content": "This is a beautifully crafted comment, expressing a thoughtful and engaging response to the post. It highlights key points and adds valuable insight to the conversation.",
"post": {
"id": 1,
"title": "The Future of AI in Education",
"content": "Exploring the impact of artificial intelligence on modern education systems.",
"tags": [
{
"id": 3,
"name": "nostrum",
"description": "Ab nam voluptas rem velit ratione quidem quo."
},
{
"id": 9,
"name": "aut",
"description": "Corrupti soluta provident sapiente soluta."
}
],
"created_at": "2024-11-10T13:58:06.000000Z",
"updated_at": "2024-11-10T13:58:06.000000Z"
}
}
}
Try Now
fetch('https://simplecrudapi.com/api/comments', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
'post_id': 1,
'content': 'This is a beautifully crafted comment, expressing a thoughtful and engaging response to the post. It highlights key points and adds valuable insight to the conversation.'
})
})
.then(response => response.json())
.then(json => console.log(json))
.catch(error => console.error('Error posting data:', error));