Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@types/axios

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/axios

Stub TypeScript definitions entry for axios, which provides its own types definitions

  • 0.14.0
  • ts2.0
  • ts2.1
  • npm
  • Socket score

Version published
Weekly downloads
513K
increased by4.47%
Maintainers
1
Weekly downloads
 
Created

What is @types/axios?

@types/axios provides TypeScript type definitions for the axios HTTP client, enabling developers to use axios with TypeScript and benefit from type checking and autocompletion.

What are @types/axios's main functionalities?

Basic GET Request

This feature allows you to make a basic GET request to a specified URL and handle the response or any errors that occur.

const axios = require('axios');
axios.get('https://api.example.com/data')
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error(error);
  });

POST Request with Data

This feature allows you to make a POST request to a specified URL with a data payload and handle the response or any errors that occur.

const axios = require('axios');
axios.post('https://api.example.com/data', {
  key1: 'value1',
  key2: 'value2'
})
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error(error);
  });

Setting Custom Headers

This feature allows you to set custom headers for a request, such as an Authorization header for authenticated requests.

const axios = require('axios');
axios.get('https://api.example.com/data', {
  headers: {
    'Authorization': 'Bearer token'
  }
})
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error(error);
  });

Handling Response Types

This feature allows you to specify the response type for a request, such as 'json', 'text', 'blob', etc.

const axios = require('axios');
axios.get('https://api.example.com/data', {
  responseType: 'json'
})
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error(error);
  });

Interceptors

This feature allows you to set up interceptors to run code or modify requests/responses before they are handled by then or catch.

const axios = require('axios');
axios.interceptors.request.use(config => {
  console.log('Request was sent');
  return config;
}, error => {
  return Promise.reject(error);
});
axios.interceptors.response.use(response => {
  console.log('Response received');
  return response;
}, error => {
  return Promise.reject(error);
});

Other packages similar to @types/axios

FAQs

Package last updated on 07 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc