0
votes

I am trying to access the Feedly API via my nuxtjs site. To do so, I am using the nuxt-axios module.

To get started, I take note of the Feedly API instructions:

We offer a standard OAuth 2.0 authentication module which provide the application an OAuth access token. Most endpoints expect an Authorization header.

$ curl -H 'Authorization: OAuth [your developer access token]' https://cloud.feedly.com/v3/profile

I now attempt to integrate this into nuxtjs-axios.

First, I set up my nuxt-config.js file:

export default {
  ...
  plugins: [{ src: `~/plugins/axios.js` }],
  modules: [
    '@nuxtjs/axios',
  ],
  axios: {
    credentials: true
  },

  env: {
    FEEDLY_ACCESS_TOKEN:
      [MY_FEEDLY_DEV_ACCESS_TOKEN]
  },
  ...
}

I then create a axios.js plugin in the plugins folder (which is imported into the nuxt-config.js file that I noted above):

export default function({ $axios }) {
  $axios.setHeader('Authorization', `OAuth ${process.env.FEEDLY_ACCESS_TOKEN}`)
}

The problem is that I have no idea what I'm supposed to put in the axios.js plugin file --- or even if that is the right way to do this. What I did is really just a stab in the dark.

So my question is, how can I implement the Feedly API into nuxtjs using the nuxtjs-axios module?

Thanks.

2

2 Answers

0
votes

Use interceptor:

// Add a request interceptor
axios.interceptors.request.use(function (config) {
    // Do something before request is sent
    return config;
  }, function (error) {
    // Do something with request error
    return Promise.reject(error);
  });

// Add a response interceptor
axios.interceptors.response.use(function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    return response;
  }, function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    return Promise.reject(error);
  });

https://github.com/axios/axios/blob/master/README.md#interceptors

0
votes

What I've understood of the nuxt-axios documentation is that the plugin.axios file is used for adding "default" behavior (axios helpers: https://axios.nuxtjs.org/helpers/)

I think that you've got the plugin right (if the token is the only thing you need to add to your header).

With the nuxt-axios enabled you can now use the this.$axios.get/post.

Have you tried to run a component with:

this.$axios.get('**feedly_url_api_url_here**').then(response)....