static loadTodos() {
    let options = {
      url: apiBaseUrl,
      method: 'GET'
    };

    return axios(options).then(response => response.data as Todo[]);
  }
  static toggleTodo(id: number) {
    let options = {
      url: `${apiBaseUrl}/toggle`,
      data: {
        id: id
      },
      method: 'POST'
    };

    return axios(options).then(response => response.data as Todo);
  }
  static addTodo(text: string) {
    let options = {
      url: apiBaseUrl,
      data: {
        text: text
      },
      method: 'POST'
    };

    return axios(options).then(response => response.data as Todo);
  }
/**
Creates a webrequest to the given path.
*/
function createRequest<T>(path: string, data: Object = {}) {
    //Result should be in JSON
    data["format"] = "json";

    const request = Axios({
        url: `https://nominatim.openstreetmap.org/${path}`,
        method: "GET",
        params: data,
        responseType: "json",
    });

    return request;
};
Example #5
0
export default
    function({ method = 'get', headers = {}, url='', params = {}, data = {} } = {}){
        if(!_.isFunction(axios[method]))
            return Promise.reject({
                code    : 500,
                message : `Error: HTTP method "${method}" is undefined.`
            });

        method = method.toLowerCase();

        return axios({
                url,
                method,
                params, // the URL parameters to be sent with the request
                data,   // the data to be sent as the request body, only applicable for request methods 'PUT', 'POST', and 'PATCH'
                headers : commonHTTPHeaders
            })
            .then(HTTPSuccessFn)
            .catch(HTTPFailedFn);
    };
Example #6
0
  return (dispatch: any) => {
    const { method, url, requestId, requestHeaders, tabId } = payload.payload.requestDetails;
    const requestHeadersObject = requestHeaders
      ? requestHeaders.reduce(
          (accumulatedObj = {}, reqHeaderNameValuePair: reqHeaderNameValuePair) => {
            accumulatedObj[reqHeaderNameValuePair.name] = reqHeaderNameValuePair.value;
            return accumulatedObj;
          },
          {}
        )
      : {};

    dispatch(fetchingResponse(tabId,requestId,true));

    axios({
      method,
      url,
      requestHeadersObject
    })
      .then(({ data, headers }: axios.AxiosResponse) => {
        const stringifiedData = headers["content-type"].includes("json")
          ? JSON.stringify(data, null, 2)
          : data;
        dispatch(fetchSuccess("", requestId, tabId));
        dispatch(handleRespTextChange(stringifiedData, requestId, tabId));
        dispatch(fetchSuccess(stringifiedData, requestId, tabId));
      })
      .catch(() => {
        dispatch(
          fetchFailure(
            "Couldn't connect to server. Check your connection and try again.",
            requestId,
            tabId
          )
        );
      })
      .finally(()=>{
        dispatch(fetchingResponse(tabId,requestId,false));
      });
  };
 return (dispatch, getState) => {
     let state = getState().auth;
     if (state) {
         // https://github.com/mzabriskie/axios/issues/312
         axios<{}>({
             method: "delete",
             url: API.current.usersPath,
             data: payload,
             params: { force: true }
         })
             .then(resp => {
                 alert("We're sorry to see you go. :(");
                 Session.clear();
                 window.location.href = "/";
             })
             .catch((e: AxiosErrorResponse) => {
                 error(prettyPrintApiErrors(e));
             });
     } else {
         throw new Error("Impossible");
     }
 };