text: export class Api {
    url= "";
    init= {};
    revive = (key, value) => {
      if (value !== null && value !== undefined) {
        if(/\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2]\d|3[0-1])T(?:[0-1]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+|)(?:Z|(?:\+|-)(?:\d{2}):?(?:\d{2}))/.exec(value)) {
          return new Date(value);
        }
      }
      return value;
    };
    post = (url, data) => {
      return new Promise( (resolve, reject) => {
        let formData = new FormData();
        Object.keys(data).forEach((key) => {
          formData.append(key, data[key])
        });
        fetch(url, {
          ...this.init,
          method: 'post',
          body: formData,
        }).then((resp) => {
          if(resp.ok) {
            resp.text().then((txt)=> {
              const output = JSON.parse(txt, this.revive);
              resolve(output);
            });
          }
          else {
            reject({status: resp.status, statusText: resp.statusText, reason: null});
          }
        }).catch((e) => {
          reject({status: null, statusText: null, reason: '' + e});
        })
      });
    };
    get = (url, data) => {
      return new Promise( (resolve, reject) => {
        const u = new URL(url);
        Object.keys(data).forEach((key) => {
          u.searchParams.append(key, data[key])
        });
        fetch(u.toString(), {
          ...this.init,
          method: 'get'
        }).then((resp) => {
          if(resp.ok) {
            resp.text().then((txt)=> {
            const output = JSON.parse(txt, this.revive);
              resolve(output);
            });
          }
          else {
            reject({status: resp.status, statusText: resp.statusText, reason: null});
          }
        }).catch((e) => {
          reject({status: null, statusText: null, reason: '' + e});
        })
      });
    };
    /**
    * @param {Date} input
    * @param {string} method 'get' or 'post'
    * @returns {Promise<Date>}
    */
    dateTime = (input, method = 'post') => {
      const data = {};
      data.input = JSON.stringify(input);
      if(method === 'get') return this.get(`${this.url}/dateTime`, data);
      return this.post(`${this.url}/dateTime`, data);
    }
    /**
    * @param {Date} input
    * @param {string} method 'get' or 'post'
    * @returns {Promise<Date>}
    */
    dateTimeNullable = (input, method = 'post') => {
      const data = {};
      data.input = JSON.stringify(input);
      if(method === 'get') return this.get(`${this.url}/dateTimeNullable`, data);
      return this.post(`${this.url}/dateTimeNullable`, data);
    }
  }
  
  export const api = new Api();
  export default api;
  