How to use the mithril.request function in mithril

To help you get started, we’ve selected a few mithril examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TwoRavens / TwoRavens / assets / app / modes / dataset.js View on Github external
async function uploadDataset() {

    if (datasetPreferences.upload.name.length === 0) return;
    if (datasetPreferences.upload.files.length === 0) return;
    let body = new FormData();
    body.append('metadata', JSON.stringify(Object.assign({}, datasetPreferences.upload, {files: undefined})));
    datasetPreferences.upload.files.forEach(file => body.append('files', file));

    // initial upload
    let response = await m.request({
        method: "POST",
        url: "user-workspaces/upload-dataset",
        body,
    });


    if (response.success) {
        location.reload();  // Restart!  Should load the new dataset
        return;
    } else {
        // clear files list
        // MS: commented this out... if it fails, shouldn't we keep the state so the user can fix it?
        // datasetPreferences.upload.files = [];
    }

    console.log('Upload dataset response: ' + response.message);
github TwoRavens / TwoRavens / assets / app / app.js View on Github external
export async function makeRequest(url, data) {
    // console.log('url:', url);
    // console.log('POST:', data);
    let res;
    try {
        res = await m.request(url, {method: 'POST', data: data});
        // console.log('response:', res);
        // oftentimes rook fails with a {warning: '...'} JSON
        if (res && 'warning' in res && Object.keys(res).length === 1) {
            // alertWarn('Warning: ' + res.warning);
            solverD3M.end_ta3_search(false, res.warning);
        }
    } catch(err) {
        solverD3M.end_ta3_search(false, err);
        cdb(err);
        alertError(`Error: call to ${url} failed`);
    }

   /*
    // call end_ta3_search if status != OK
    // status may be in different places for different calls though, and this is not worth doing at the moment
    let myreg = /d3m-service/g;
github hyperledger-labs / sawtooth-healthcare / web / src / models / PatientDetails.js View on Github external
load: function(patient_pkey, doctor_pkey) {
        return m.request({
            method: "GET",
            url: "/api/sec_pulse/" + patient_pkey + "/" + doctor_pkey,
//            withCredentials: true,
        })
        .then(function(result) {
            PatientDetails.error = ""
            PatientDetails.pulseList = result.data
        })
        .catch(function(e) {
            console.log(e)
            PatientDetails.error = e.message
            PatientDetails.pulseList = []
        })
    },
github CenterForOpenScience / osf.io / website / static / js / home-page / donateBannerPlugin.js View on Github external
controller: function() {
        var self = this;
        self.banner = m.prop();
        self.bannerLoaded = m.prop(false);

        // Load banner
        var domain = lodashGet(window, 'contextVars.apiV2Domain', '');
        var bannerUrl =   domain + '_/banners/current/';
        var bannerPromise = m.request({method: 'GET', url: bannerUrl}, background=true);
        bannerPromise.then(function(result){
            self.banner(result.data);
            self.bannerLoaded(true);
        }, function(error) {
            Raven.captureMessage('Error in request to ' + bannerUrl, {
                extra: {error: error}
            });
        });
    },
    view : function(ctrl) {
github TwoRavens / TwoRavens / assets / EventData / app / subsets / Actor.js View on Github external
'type': currentTab
    };

    function updateActorListing(data) {
        if ('source' in data) app.subsetMetadata['Actor']['<source>'] = data.source || [];
        if ('target' in data) app.subsetMetadata['Actor'][''] = data.target || [];
        scrolledPageSize = defaultPageSize;
        loadDataHelper(currentTab, "full", defaultPageSize);
        waitForQuery--;
        m.redraw();
    }

    let failedUpdateActorListing = () =&gt; waitForQuery--;
    waitForQuery++;
    m.redraw();
    m.request({
        url: app.subsetURL,
        data: query,
        method: 'POST'
    }).then(updateActorListing).catch(failedUpdateActorListing);
}
github gocd / gocd / server / webapp / WEB-INF / rails / webpack / helpers / api_request_builder.ts View on Github external
private static makeRequest(url: string,
                             method: string,
                             apiVersion?: ApiVersion,
                             options?: Partial): Promise&gt; {
    const headers = this.buildHeaders(method, apiVersion, options);

    let payload: any;
    if (options &amp;&amp; options.payload) {
      payload = options.payload;
    }

    return m.request({
                                       url,
                                       method,
                                       headers,
                                       body: payload,
                                       extract: _.identity,
                                       deserialize: _.identity,
                                       config: (xhr) =&gt; {
                                         if (options &amp;&amp; options.xhrHandle) {
                                           options.xhrHandle(xhr);
                                         }
                                       }
                                     }).then((xhr: XMLHttpRequest) =&gt; {
      return ApiResult.from(xhr);
    }).catch((reason) =&gt; {
      const unknownError = "There was an unknown error performing the operation.";
      try {
github catarse / catarse.js / src / vms / reward-vm.js View on Github external
const createReward = (projectId, rewardData) => m.request({
    method: 'POST',
    url: `/projects/${projectId}/rewards.json`,
    data: {
        reward: rewardData
    },
    config: h.setCsrfToken
});
github gocd / gocd / server / src / main / webapp / WEB-INF / rails / webpack / helpers / api_request_builder.ts View on Github external
private static makeRequest(url: string,
                             method: string,
                             apiVersion?: ApiVersion,
                             options?: Partial): Promise&gt; {
    const headers = this.buildHeaders(method, apiVersion, options);

    let payload: any;
    if (options &amp;&amp; options.payload) {
      payload = options.payload;
    }

    return m.request({
                                       url,
                                       method,
                                       headers,
                                       body: payload,
                                       extract: _.identity,
                                       deserialize: _.identity,
                                       config: (xhr) =&gt; {
                                         if (options &amp;&amp; options.xhrHandle) {
                                           options.xhrHandle(xhr);
                                         }
                                       }
                                     }).then((xhr: XMLHttpRequest) =&gt; {
      return ApiResult.from(xhr);
    }).catch((reason) =&gt; {
      const unknownError = "There was an unknown error performing the operation.";
      try {
github ArthurClemens / mithril-infinite / packages / examples / src / paging / index.js View on Github external
const getData = pageNum =>
  m.request({
    method: "GET",
    url: "data/paging/page-" + pageNum + ".json"
  });
github catarse / catarse.js / legacy / src / vms / payment-vm.js View on Github external
const updateContributionData = (contribution_id, project_id) => {
        const contributionData = {
            anonymous: fields.anonymous(),
            payer_document: fields.ownerDocument(),
            payer_name: fields.completeName(),
            address_attributes: fields.address().getFields(),
            card_owner_document: creditCardFields.cardOwnerDocument()
        };

        return m.request({
            method: 'PUT',
            url: `/projects/${project_id}/contributions/${contribution_id}.json`,
            data: { contribution: contributionData },
            config: setCsrfToken
        })
        .catch((error) => {
            h.captureException(error);
            throw error;
        });
    };