POST /add-comments

Adds a new comment to the artist page you are on.

Endpoint URL

http://127.0.0.1:8080/add-comments

JSON body parameters

ArtistName

sting

The artist's name you wish to add a comment to.

Comment

string

The comment itself.

Example Code

form2.addEventListener('submit', async function (event) {
    event.preventDefault();
    
    // Formatting the data to be sent to server-side
    const ArtistName = document.getElementById('ArtistNameHeader').innerHTML;
    const Comment = document.getElementById('comment-input').value;
    const formData = new FormData(form2);
    formData.append('ArtistName', ArtistName);
    formData.append('Comment', Comment);
    const dataJson = JSON.stringify(Object.fromEntries(formData.entries()));
    document.getElementById('comment-input').value = '';

    try {
        const response = await fetch('http://127.0.0.1:8080/add-comments', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: dataJson
        });
        if (!response.ok) {
            throw new Error('Respond Status is' + response.status);
        }

    } catch (error) {
        alert(error);
    }
});

Example Response

{
    "ArtistName": "Tory Lanez",
    "Comment": "Great artist!"
}

Response Code

  • 200 OK : The comment was successfully added. The response body will contain the comment that was added.

  • 404 Not Found : The artist was not found and an error message will be displayed.

Response Field

ArtistName

sting

The artist's name you wish to add a comment to.

Comment

string

The comment itself.

Last updated