Skip to content

Instantly share code, notes, and snippets.

@nOy39
Forked from drucoder/requests.js
Created June 18, 2018 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nOy39/dbf0498eaf4f9b881ea8819b8ada445f to your computer and use it in GitHub Desktop.
Save nOy39/dbf0498eaf4f9b881ea8819b8ada445f to your computer and use it in GitHub Desktop.
Spring Boot REST: тестироем rest методы
// GET all
fetch('/message/').then(response => response.json().then(console.log))
// GET one
fetch('/message/2').then(response => response.json().then(console.log))
// POST add new one
fetch(
'/message',
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text: 'Fourth message (4)', id: 10 })
}
).then(result => result.json().then(console.log))
// PUT save existing
fetch(
'/message/4',
{
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text: 'Fourth message', id: 10 })
}
).then(result => result.json().then(console.log));
// DELETE existing
fetch('/message/4', { method: 'DELETE' }).then(result => console.log(result))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment