jsonjumble.js 631 B

12345678910111213141516171819202122232425
  1. class JsonJumble {
  2. constructor(user) {
  3. this.user = user;
  4. }
  5. async get(key) {
  6. const dataEndpoint = `https://jsonjumble.com/v1/data`;
  7. const result = await fetch(`${dataEndpoint}/${this.user}/${key}`, {
  8. method: "GET",
  9. mode: "cors",
  10. cache: "no-cache",
  11. credentials: "same-origin",
  12. headers: {
  13. "Content-Type": "application/json",
  14. },
  15. redirect: "follow",
  16. referrerPolicy: "no-referrer",
  17. });
  18. if (result.status == 200) {
  19. return await result.json()
  20. } else {
  21. throw new Exception(`${result.status} ${result.statusText}: Retrieving ${dataEndpoint}/${this.user}/${key} was not successful.`)
  22. }
  23. }
  24. }