axios

Axios returns promise pending

旧时模样 提交于 2021-01-28 00:59:33
问题 i want this function to return either true or false, instead I get /** * Sends request to the backend to check if jwt is valid * @returns {boolean} */ const isAuthenticated = () => { const token = localStorage.getItem('jwt'); if(!token) return false; const config = {headers : {'x-auth-token' : token}}; const response = axios.get('http://localhost:8000/user' , config) .then(res => res.status === 200 ? true : false) .catch(err => false); return response; } export default isAuthenticated; I

The difference between axios and supertest in NodeJS

倾然丶 夕夏残阳落幕 提交于 2021-01-27 19:40:38
问题 Both Axios and Supertest can send HTTP requests to a server. But why is Supertest used for testing while Axios is used for practice API calls? 回答1: There are two reasons to use Supertest rather than a vanilla request library like Axios (or Superagent, which Supertest wraps): It manages starting and binding the app for you, making it available to receive the requests: You may pass an http.Server , or a Function to request() - if the server is not already listening for connections then it is

Client side convert png file stream into file object

孤街醉人 提交于 2021-01-27 19:30:03
问题 I get 'png image stream' from an API.The API uses gm(GraphicsMagick) to generate image file stream. In client side I am using axios to make API call. Successfully I am able to receive the response.In client side I have to convert this file stream into a file object. I use the below code for that. But it didn't help to get the actual image back. Help me to convert the file stream into a valid image file object in client side Code: const imageStream = response.data; const blob = new Blob(

The difference between axios and supertest in NodeJS

孤街醉人 提交于 2021-01-27 19:17:07
问题 Both Axios and Supertest can send HTTP requests to a server. But why is Supertest used for testing while Axios is used for practice API calls? 回答1: There are two reasons to use Supertest rather than a vanilla request library like Axios (or Superagent, which Supertest wraps): It manages starting and binding the app for you, making it available to receive the requests: You may pass an http.Server , or a Function to request() - if the server is not already listening for connections then it is

axios - how to deal with big integers

Deadly 提交于 2021-01-27 18:53:22
问题 Here is my request: axios.get(url) .then(res => { console.log(res.data) }) The output is { value: 156144277082605255 } But should be { value: 156144277082605250 } How to deal with Big Integers in this case? I tried to use json-bigint But since I am getting response.data from axios as object - it doesn't help. 回答1: My colleague answered the question: I had to transform my response.data into string. (you may wonder - why the useless function - just to redefine default behavior, which parses

Change axios Response Schema

夙愿已清 提交于 2021-01-27 18:28:41
问题 As axios GitHub page states, default response of axios request is: { // `data` is the response that was provided by the server data: {}, // `status` is the HTTP status code from the server response status: 200, // `statusText` is the HTTP status message from the server response statusText: 'OK', // `headers` the headers that the server responded with // All header names are lower cased headers: {}, // `config` is the config that was provided to `axios` for the request config: {}, // `request`

POST request to Graph API fails with Bad Request

馋奶兔 提交于 2021-01-27 10:54:09
问题 I am developing a script to access the Graph API to read all users in our AD. I am performing a request with AXIOS via: let response; try { response = await axios.post(`https://login.microsoftonline.com/${config.get('azure.tenant')}/oauth2/v2.0/token`, { client_id: config.get('azure.appId'), scope: config.get('azure.scope'), client_secret: config.get('azure.secret'), grant_type: config.get('azure.grantType') }); } catch (e) { res.send(e); } This fails, though, with: { "message": "Request

Jest mockResolvedValue is not a function

匆匆过客 提交于 2021-01-27 06:06:37
问题 I'm getting an error mocking my api call TypeError: Cannot read property 'mockResolvedValue" of undefined and cannot figure out why. I'm utilizing jest to test my api fetch call function. This is my function I'm exporting: //file amData.jsx const axios = require('axios'); async function fetchAssetManagerSummary() { const response = await axios.get("https://fr-assetmanager.azurewebsites.net/File/GetOverview?runDat=04/01/2020"); return response.data; } module.exports = fetchAssetManagerSummary;

Jest mockResolvedValue is not a function

痞子三分冷 提交于 2021-01-27 06:04:38
问题 I'm getting an error mocking my api call TypeError: Cannot read property 'mockResolvedValue" of undefined and cannot figure out why. I'm utilizing jest to test my api fetch call function. This is my function I'm exporting: //file amData.jsx const axios = require('axios'); async function fetchAssetManagerSummary() { const response = await axios.get("https://fr-assetmanager.azurewebsites.net/File/GetOverview?runDat=04/01/2020"); return response.data; } module.exports = fetchAssetManagerSummary;

Getting Request failed with status code 403 with axios get

為{幸葍}努か 提交于 2021-01-25 07:09:54
问题 I have setup my axios like this: const agent = new https.Agent({ rejectUnauthorized: false }); and sending a get call like this: let data = await axios.get('https://www.skechers.com/en-us/', { httpsAgent: agent }); but with some urls my request fails with this error: Request failed with status code 403 what would be the possible reason to cause this error. I have tried setting up headers as follow but still getting the error let data = await axios.get(url, { httpsAgent: agent, headers: {