Socket
Socket
Sign inDemoInstall

@nuxtjs/axios

Package Overview
Dependencies
4
Maintainers
4
Versions
86
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nuxtjs/axios


Version published
Maintainers
4
Created

Package description

What is @nuxtjs/axios?

@nuxtjs/axios is a Nuxt.js module that integrates the Axios HTTP client with Nuxt.js applications. It simplifies making HTTP requests in a Nuxt.js project by providing a consistent API and additional features tailored for Nuxt.js.

What are @nuxtjs/axios's main functionalities?

Making GET Requests

This feature allows you to make GET requests to fetch data from an API endpoint. The example demonstrates how to use the $axios.$get method within the asyncData lifecycle hook to fetch data before rendering the page.

async asyncData({ $axios }) {
  const data = await $axios.$get('https://api.example.com/data');
  return { data };
}

Making POST Requests

This feature allows you to make POST requests to send data to an API endpoint. The example shows how to use the $axios.$post method to submit form data to a server.

async submitForm({ $axios }, formData) {
  const response = await $axios.$post('https://api.example.com/submit', formData);
  return response;
}

Setting Base URL

This feature allows you to set a base URL for all Axios requests. The example demonstrates how to configure the base URL in the Nuxt.js configuration file.

export default {
  axios: {
    baseURL: 'https://api.example.com'
  }
}

Handling Errors

This feature allows you to handle errors that occur during HTTP requests. The example shows how to use a try-catch block to catch errors and handle them appropriately within the asyncData lifecycle hook.

async asyncData({ $axios, error }) {
  try {
    const data = await $axios.$get('https://api.example.com/data');
    return { data };
  } catch (e) {
    error({ statusCode: 500, message: 'Internal Server Error' });
  }
}

Other packages similar to @nuxtjs/axios

Changelog

Source

5.3.1 (2018-03-31)

<a name="5.3.0"></a>

Readme

Source

📦 Axios Module

Secure and Easy Axios integration with Nuxt.js.


✅ Features

✓ Automatically set base URL for client & server side

✓ Exposes setToken function to $axios so we can easily and globally set authentication tokens

✓ Automatically enables withCredentials when requesting to base URL

✓ Proxy request headers in SSR (Useful for auth)

✓ Fetch Style requests

✓ Integrated with Nuxt.js Progressbar while making requests

✓ Integrated with Proxy Module

✓ Auto retry requests with axios-retry

📖 Read Documentation

📑 License

MIT License - Nuxt Community

FAQs

Last updated on 31 Mar 2018

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc