xm4dn355x

global fetch funcs

Apr 15th, 2021
407
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const baseURI = '/imonitor/api/v1/';
  2.  
  3. async function getCategoriesList() {
  4.     const res = await fetch(`${baseURI}category/list`);
  5.     return res.json()
  6. }
  7.  
  8. async function getLocationsList() {
  9.     const res = await fetch(`${baseURI}location/list`);
  10.     return res.json();
  11. }
  12.  
  13. async function getRegionsList() {
  14.     const res = await fetch(`${baseURI}location/region/list`);
  15.     return res.json();
  16. }
  17.  
  18. async function getCitiesList() {
  19.     const res = await fetch(`${baseURI}location/city/list`);
  20.     return res.json();
  21. }
  22.  
  23. async function getPostList() {
  24.         const res = await fetch(`${baseURI}post/list`);
  25.         return res.json();
  26. }
  27.  
  28. async function getPostById(id) {
  29.     const res = await fetch(`${baseURI}post/${id}/`);
  30.     return res.json();
  31. }
  32.  
  33. async function postPost(data) {
  34.     const res = await fetch(`${baseURI}post/`, {
  35.         method: 'POST',
  36.         mode: 'cors',
  37.         cache: 'no-cache',
  38.         credentials: 'same-origin',
  39.         headers: {'Content-Type': 'application/json'},
  40.         redirect: 'follow',
  41.         referrerPolicy: 'no-referrer',
  42.         body: JSON.stringify(data)
  43.     });
  44.     return res.json();
  45. }
  46.  
  47. function removeOptions(selectElement) {
  48.     let i, L = selectElement.options.length - 1;
  49.     for(i = L; i >= 0; i--) {
  50.         selectElement.remove(i);
  51.     }
  52. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×