1

We are currently using the Third-party HTTP Service provided by MongoDB in order to make HTTP requests to the outside world from within our app running in Atlas App Services. As per their documentation, this will be deprecated in December 2022.

However, I can't find an alternative for the future - what will be the preferred way to make HTTP requests from within Atlas App Services Apps?

1 Answer 1

3

I was in similar situation before as you are. But then I realised that App Service team actually simplifies it by adding support for dependencies.

So, I can import standard axios library and starts using it seamlessly as

exports = async function(arg){
  const axios = require('axios'); // is allowed here

  axios.get('https://coderower.com')
    .then(response => {
       console.log(response.data);
    })
    .catch(error => {
      console.log(error);
    });
  
  
  return {success: true}
};

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Ishaan, this was the solution. One caveat that took me a while to figure out was that "require" isn't allowed at the top level - would you mind editing your answer to make this more clear to readers?
For anyone reading this in 2023. Axios ONLY works with 1.0.0-alpha.1. Most other versions will throw import errors.
@RoguePanda As of 04/22/2023, axios 1.2.0 works in Atlas functions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.