api.js 828 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. const BASE_URL = "https://kirkleon.ddns.net/vacation-planner/api"
  2. export const getHealth = async () => {
  3. const res = await fetch(BASE_URL + "/");
  4. if (!res.ok) {
  5. throw new Error(res.statusText);
  6. }
  7. const { status } = await res.json();
  8. return status;
  9. }
  10. export const getAvailability = async () => {
  11. const res = await fetch(BASE_URL + "/availability");
  12. if (!res.ok) {
  13. throw new Error(res.statusText);
  14. }
  15. return await res.json();
  16. }
  17. export const setAvailability = async (name, availability) => {
  18. const res = await fetch(
  19. BASE_URL + "/availability",
  20. {
  21. method: "POST",
  22. headers: {
  23. "Content-Type": "application/json",
  24. },
  25. body: JSON.stringify({ name, availability }),
  26. }
  27. );
  28. if (!res.ok) {
  29. throw new Error(res.statusText);
  30. }
  31. return await res.json();
  32. }