fetch_sample.js 743 B

1234567891011121314151617181920212223242526272829303132
  1. //index
  2. //http://localhost/mint/v2/public/api/courses
  3. //show
  4. //http://localhost/mint/v2/public/api/courses/2
  5. //stor
  6. let data = {title:"visuddhimagga"};
  7. fetch("http://localhost/mint/v2/public/api/courses",{
  8. body:JSON.stringify(data),
  9. headers:{
  10. 'content-type':'application/json'
  11. },
  12. method:'POST'
  13. }).then(response =>response.json());
  14. //update
  15. fetch("http://localhost/mint/v2/public/api/courses/1?title=newtitle1",{
  16. headers:{
  17. 'content-type':'application/json'
  18. },
  19. method:'PUT'
  20. }).then(response =>response.json());
  21. //delete
  22. fetch("http://localhost/mint/v2/public/api/courses/1",{
  23. headers:{
  24. 'content-type':'application/json'
  25. },
  26. method:'DELETE'
  27. }).then(response =>response.json());