Guest User

Untitled

a guest
Jun 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. // GET all
  2. fetch('/message/').then(response => response.json().then(console.log))
  3.  
  4. // GET one
  5. fetch('/message/2').then(response => response.json().then(console.log))
  6.  
  7. // POST add new one
  8. fetch(
  9. '/message',
  10. {
  11. method: 'POST',
  12. headers: { 'Content-Type': 'application/json' },
  13. body: JSON.stringify({ text: 'Fourth message (4)', id: 10 })
  14. }
  15. ).then(result => result.json().then(console.log))
  16.  
  17. // PUT save existing
  18. fetch(
  19. '/message/4',
  20. {
  21. method: 'PUT',
  22. headers: { 'Content-Type': 'application/json' },
  23. body: JSON.stringify({ text: 'Fourth message', id: 10 })
  24. }
  25. ).then(result => result.json().then(console.log));
  26.  
  27. // DELETE existing
  28. fetch('/message/4', { method: 'DELETE' }).then(result => console.log(result))
Add Comment
Please, Sign In to add comment