How to use the axios.put function in axios

To help you get started, weโ€™ve selected a few axios 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 Lambda-School-Labs / Airtable-ORM / Request.js View on Github external
let promise;
      if (Request.printRequests) {
        console.log(`\nSending ${this.type.toUpperCase()} Request: ${url}`);
        console.log(`\tHeaders: ${JSON.stringify(headers, null, 2).replace(/(?:\r\n|\r|\n)/g, '\n\t')}`);
        console.log(`\tParameters: ${JSON.stringify(this.parameters, null, 2).replace(/(?:\r\n|\r|\n)/g, '\n\t')}`);
        console.log(`\tData: ${JSON.stringify(this.data, null, 2).replace(/(?:\r\n|\r|\n)/g, '\n\t')}\n`);
      }
      switch(this.type.toLowerCase()) {
        case 'get':
          promise = axios.get(url, { params: this.parameters, headers, withCredentials: true });
          break;
        case 'post':
          promise = axios.post(url, this.data, { params: this.parameters, headers, withCredentials: true });
          break;
        case 'put':
          promise = axios.put(url, this.data, { params: this.parameters, headers, withCredentials: true });
          break;
        case 'patch':
          promise = axios.patch(url, this.data, { params: this.parameters, headers, withCredentials: true });
          break;
        case 'delete':
          promise = axios.delete(url, { params: this.parameters, headers, withCredentials: true });
          break;
        default:
          return reject(new Error('RequestError: Unknown type encountered during request.send execution. Type: ' + this.type + '.'));
      }
      if (promise !== undefined) {
        promise.then((...args) => {
          if (this.success !== undefined)
            this.success(...args);
          resolve(...args);
        }).catch((...args) => {
github research-software-directory / research-software-directory / admin / src / components / Resource / index.tsx View on Github external
save = () => {
    this.setState({ saving: true });
    const { resourceType, id } = this.props.match.params;
    const { backendUrl } = this.props.settings;
    axios
      .put(
        `${backendUrl}/${resourceType}/${id}?save_history`,
        this.state.data,
        {
          headers: {
            Authorization: `Bearer ${this.props.jwt.token}`
          }
        }
      )
      .then(() => {
        this.setState({ saving: false });
        this.props.messageToastr("Saved");
      })
      .catch(response => {
        this.setState({ saving: false });
        this.props.errorToastr(JSON.stringify(response.response.data));
github codenesium / samples / AdventureWorks / AdventureWorks.Api.TypeScript / src / react / src / components / unitMeasure / unitMeasureEditForm.tsx View on Github external
submit = (model: UnitMeasureViewModel) => {
    let mapper = new UnitMeasureMapper();
    axios
      .put(
        Constants.ApiEndpoint +
          ApiRoutes.UnitMeasures +
          '/' +
          this.state.model!.unitMeasureCode,
        mapper.mapViewModelToApiRequest(model),
        {
          headers: {
            'Content-Type': 'application/json',
          },
        }
      )
      .then(
        resp => {
          let response = resp.data as CreateResponse<
            Api.UnitMeasureClientRequestModel
github chanzuckerberg / idseq-web / app / assets / src / components / views / samples / ProjectSettingsModal / UserManagementForm.jsx View on Github external
handleAddUser = () => {
    const { csrf, onUserAdded, project } = this.props;
    const { name, email } = this.state;

    const fieldsValidation = {
      email: StringHelper.validateEmail(email),
      name: StringHelper.validateName(name),
    };

    if (Object.values(fieldsValidation).every(valid => !!valid)) {
      this.setState({
        statusClass: cs.infoMessage,
        statusMessage: "Sending invitation",
      });
      axios
        .put(`/projects/${project.id}}/add_user`, {
          user_name_to_add: name,
          user_email_to_add: email,
          authenticity_token: csrf,
        })
        .then(() => {
          onUserAdded(name, email);
          this.setState({
            statusClass: cs.successMessage,
            statusMessage: "Invitation sent! User added.",
            name: "",
            email: "",
          });
        });
    } else {
      let invalidFieldsString = Object.keys(fieldsValidation)
github funnyjerry / react-native-marketplace-typescript-app / src / api / auth.ts View on Github external
const put = (url, data, options = {}) => {
	const abort = Axios.CancelToken.source();
	const id = setTimeout(() => abort.cancel(`Timeout of ${config.timeout}ms.`), config.timeout);
	return Axios.put(url, data, { cancelToken: abort.token, ...options }).then((response) => {
		clearTimeout(id);
		return response;
	});
};
github jponge / vertx-in-action / part2-steps-challenge / user-webapp / src / views / Home.vue View on Github external
sendUpdate() {
        const data = {
          city: this.city,
          email: this.email,
          makePublic: this.makePublic
        }
        const config = {
          headers: {
            'Authorization': `Bearer ${DataStore.token()}`
          }
        }
        axios
          .put(`http://localhost:4000/api/v1/${DataStore.username()}`, data, config)
          .then(() => this.refreshData())
          .catch(err => {
            this.alertMessage = err.message
            this.refreshFromDataStore()
          })
      }
    },
github TugayYaldiz / vue-comment-grid / src / Comments.vue View on Github external
.then(res => {
                commentObj.id = res.data.name;
                const repliedObj = { user_id: this.userId };
                axios
                  .put(
                    this.baseURL +
                      "/commentsGrid/" +
                      this.nodeName +
                      "/replys/" +
                      commentObj.id +
                      ".json" +
                      "?auth=" +
                      this.idToken,
                    repliedObj
                  )
                  .then(res => {
                    commentObj.depth =
                      "commentsGrid/" +
                      this.nodeName +
                      "/comments/" +
github akameco / react-s3-uploader-sample / index.js View on Github external
}).then(res => {
      const options = {
        headers: {
          'Content-Type': file.type
        }
      };
      return axios.put(res.data.url, file, options);
    }).then(res => {
      const {name} = res.config.data;
github containerum / ui / src / actions / TokensActions / addTokenAction.js View on Github external
return dispatch => {
        dispatch(requestAddToken());
        let token = '';
        let browser = '';
        if (typeof window !== 'undefined' && typeof localStorage !== 'undefined') {
            token = localStorage.getItem('id_token');
            browser = localStorage.getItem('id_browser');
        }

        const api = WEB_API + '/api/tokens/' + addingToken;

        return axios.put(
            api,
            {
                headers: {
                    'Authorization': token,
                    'User-Client': browser,
                    'Content-Type': 'application/x-www-form-urlencode',
                    'Access-Control-Allow-Origin': '*',
                    'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=-1, private'
                },
                validateStatus: (status) => status >= 200 && status <= 500
            }
        )
            .then(response => {
                if (response.status === 200) {
                    dispatch(receiveAddToken(response.data));
                } else if (response.status === 401) {
github gardener / dashboard / frontend / src / utils / api.js View on Github external
function updateResource (url, data) {
  return axios.put(url, data)
}