1

I'm writing a quiz app, where the frontend GETs a question from the server database using Fetch API, then sends both question and answer again via Fetch API to django on the server, which then is supposed to check against the data base if the answer is correct or not. As of now the checking doesn't change anything on the server (though in the future it'll change points for the user depending on if the answer was correct). Should I then be using PUT or POST as method? I cannot use GET, because a GET method cannot have a body for parameters.

const setup = {
   credentials: "same-origin",
   method: 'PUT' or 'POST'?,
   body: JSON.stringify({
      "answer": 'is answer',
      "question": 'is question'
   }),
   headers: {
      "X-CSRFToken": getCookie("csrftoken"),
      "Accept": "application/json",
      "Content-Type": "application/json",
      "X-Requested-With": "XMLHttpRequest"
   },
};
const response = await fetch('/exercises/get_exercise', setup);

that's my fetch request. Also happy to hear any other comments on the code!

Val Melev
  • 154
  • 1
  • 8

1 Answers1

0

Even though you're not creating actual record on your database, I'd suggest you use POST. Think of it as you're creating a submission, or an answer record.

Possible duplicate: PUT vs. POST in REST

Waseem
  • 651
  • 1
  • 5
  • 15