api.js 797 B

123456789101112131415161718192021222324252627282930313233343536
  1. const BASE_URL = "https://hiram.services/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. }