How to use the got.put function in got

To help you get started, we’ve selected a few got 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 Streampunk / beamengine / scratch / storeWav.js View on Github external
try {
    let response = await got.post('http://localhost:3000/beams', { // eslint-disable-line no-unused-vars
      body: wavFmt.toJSON(),
      json: true,
      headers : { 'Content-Type': 'application/json' }
    }).catch(err => {
      if (err.statusCode === 409) {
        console.log('Got conflict: assuming OK.');
      } else {
        throw err;
      }
    });

    let pkt = await wavFmt.read();
    for ( ; pkt != null ; pkt = await wavFmt.read()) {
      await got.put(`http://localhost:3000/beams/${locPathPart}/stream_0/packet_${pkt.pts}`, {
        body: pkt.toJSON(),
        json: true
      });
      await got.put(
        `http://localhost:3000/beams/${locPathPart}/stream_0/packet_${pkt.pts}/data`, {
          body: pkt.data,
          headers: { 'Content-Type': 'application/octet-stream' }
        });
    }
  } catch (err) {
    console.error(err.stack);
  }

}
github apinf / platform / apinf_packages / proxy_backends / server / methods.js View on Github external
.then(res => {
            // SailsJS returnes an array of items in JSON format
            const aclRules = res.body;
            // Find the same rule as given from iteration
            const aclRuleExists = _.find(aclRules, (r) => {
              return r.id === rule.id;
            });

            // Check if ACL rule actually exists
            if (aclRuleExists) {
              // If ACL Rule aleady exists, only update it
              got.put(`${url}${apiPath}/${rule.id}`, { auth, json: true, body: data })
                .then((res1) => {
                  return res1;
                })
                .catch((err) => {
                  return err;
                });
            } else {
              // If ACL Rule does not exist on remote, then POST it
              got.post(`${url}${apiPath}`, { auth, json: true, body: data })
                .then((res1) => {
                  return res1;
                })
                .catch((err) => {
                  return err;
                });
            }
github r-hub / rhub-frontend / lib / job-to-db.js View on Github external
// to be filled later
	started: null,
	build_time: null,
	builder_machine: null,

	// these are parsed from the output logs
	result: null,
	check_output: null,
	preperror_log: null
    };

    var fullurl = urls.logdb  + '/' + doc.id;
    var _url = url.parse(fullurl);
    var dburl = _url.protocol + '//' + _url.host + _url.path;

    got.put(
	dburl,
	{ body: JSON.stringify(doc), auth: _url.auth },
	function(err, reponse) {
	callback(err);
    });
}
github semantic-release / semantic-release / test / helpers / mockserver.js View on Github external
    await pRetry(() => got.put(`http://${MOCK_SERVER_HOST}:${MOCK_SERVER_PORT}/status`, {cache: false}), {
      retries: 7,
github alex-phillips / node-clouddrive / lib / Node.js View on Github external
}, (err, stream) => {
      if (err) {
        return callback(err);
      }

      form.append('content', stream);
      let headers = form.getHeaders();
      headers.Authorization = `Bearer ${account.token.access_token}`;

      stream.on('data', chunk => {
        this.emit('uploadProgress', localPath, chunk);
      });

      Logger.verbose('Requesting nodes:files:overwrite endpoint');
      Logger.debug(`HTTP Request: PUT '${account.contentUrl}nodes/${this.getId()}/content'`);
      got.put(`${account.contentUrl}nodes/${this.getId()}/content`, {
        headers: headers,
        body: form,
        timeout: 3600000,
      })
        .then(response => {
          stream.close();
          Logger.debug(`Response returned with status code ${response.statusCode}.`);
          Logger.silly(`Response body: ${response.body}`);

          if (options.encrypt) {
            Logger.debug(`Removing encrypted cache file at ${stream.path}`);
            fs.unlinkSync(stream.path);
          }

          this.getPath((err, remotePath) => {
            if (err) {
github DrewML / chrome-webstore-upload / index.js View on Github external
return eventualToken.then(token => {
            return got.put(uploadExistingURI(extensionId), {
                headers: this._headers(token),
                body: readStream,
                json: true
            }).then(this._extractBody);
        });
    }
github nasa / cumulus / packages / api / lambdas / bootstrap.js View on Github external
async function sendResponse(event, status, data = {}) {
  const body = JSON.stringify({
    Status: status,
    PhysicalResourceId: physicalId,
    StackId: event.StackId,
    RequestId: event.RequestId,
    LogicalResourceId: event.LogicalResourceId,
    Data: data
  });

  log.info('RESPONSE BODY:\n', body);
  log.info('SENDING RESPONSE...\n');

  const r = await got.put(event.ResponseURL, {
    body,
    headers: {
      'content-type': '',
      'content-length': body.length
    }
  });
  log.info(r.body);
}
github alex-phillips / node-clouddrive / lib / Node.js View on Github external
link(idParent, callback) {
    let retval = {
      success: false,
      data: {},
    };

    Logger.verbose('Requesting nodes:children:add endpoint (link)');
    Logger.debug(`HTTP Request: PUT '${account.metadataUrl}nodes/${idParent}/children/${this.getId()}'`);
    got.put(`${account.metadataUrl}nodes/${idParent}/children/${this.getId()}`, {
      headers: {
        Authorization: `Bearer ${account.token.access_token}`,
      },
    })
      .then(response => {
        Logger.debug(`Response returned with status code ${response.statusCode}.`);
        Logger.silly(`Response body: ${response.body}`);
        retval.data = JSON.parse(response.body);

        if (response.statusCode === 200) {
          retval.success = true;
          this.replace(retval.data);

          return this.save(() => {
            return callback(null, retval);
          });
github mapbox / stork / lambda.js View on Github external
const token = process.env.GITHUB_ACCESS_TOKEN;
      const installationId = process.env.GITHUB_APP_INSTALLATION_ID;

      const query = { access_token: token };

      const config = {
        json: true,
        headers: {
          'User-Agent': 'github.com/mapbox/stork',
          Accept: 'application/vnd.github.machine-man-preview+json'
        }
      };

      const uri = `https://api.github.com/user/installations/${installationId}/repositories/${event.repoId}`;

      return got.put(`${uri}?${querystring.stringify(query)}`, config);
    })
    .then(() => callback())