axios

Axios recursion for paginating an api with a cursor

不问归期 提交于 2019-12-04 23:18:33
问题 How can I paginate an API with a cursor using axios ? I would like to recursively call this function until response.data.length < 1 and return the entire array with all items in the collection when it is done. Also, worth noting, I would have to pass the cursor into subsequent calls. function getUsers () { return axios.get('/users') // API supports a cursor param (?after=) .then(response => { // returns an array with a cursor // see response below console.log(response.data) }) } Example

process Axios POST in PHP [duplicate]

泪湿孤枕 提交于 2019-12-04 23:10:27
This question already has answers here : Issue reading HTTP request body from a JSON POST in PHP (2 answers) Closed last year . I want to send a POST request to my PHP file to handle it and store the data in the database.. I'm pretty stuck at it since $_POST stays empty whatever I try.. Can someone help me sending a post request and help me how to handle it ? My axios request: // Performing a POST request axios.post('dev/api/post.php',{ text: text, unk: unk}) .then(function(response){ console.log(response); }).catch(function (error) { console.log(error); }); And this is what I kinda tried in

Axios/XMLHttpRequest is sending GET instead of POST in production environment

倖福魔咒の 提交于 2019-12-04 21:17:41
问题 I am running into a very strange issue. We are putting an app into production and one of the POST request is turning into a POST followed directly by a GET request to the same URL and the POST is never received in the backend (Laravel). In the chrome network tab it just looks like just a GET but with Burpsuite we can see the POST request. The code responsible async store() { // This prints post console.log(this.method()); await this.form[this.method()]('/api/admin/users/' + (this.isUpdate() ?

Async/Await in Axios

你说的曾经没有我的故事 提交于 2019-12-04 19:02:04
I am trying to get a basic async/await working with Axios, any pointers would be helpful. isUserInDatabase() { axios.get(url) .then( (response) => { return response.data.data; }) }, async isUnique() { await this.isUserInDatabase() } The current problem is: You resolve your promise and don't return a new promise in isUserInDataBase method. Try some thing like that: isUserInDatabase() { return axios.get(url); } async isUnique() { try { await this.isUserInDatabase() } catch(error) { console.log(error) } } OR isUserInDatabase() { return new Promise(async (resolve,reject)) => { try { const result =

how to re-render after getting axios response in jest test

一曲冷凌霜 提交于 2019-12-04 17:28:47
My component: componentDidMount() { // Make HTTP reques with Axios axios.get(APIConfig.api_profile()).then((res) => { // Set state with result this.setState(res.data); console.log('I was triggered during componentDidMount') console.log(res) }); } And my test: //@see https://github.com/ctimmerm/axios-mock-adapter mock.onGet(APIConfig.api_profile()).reply(200, { "id_user": "1", "id_person": "1", "imageUrl": "", "email": "xyz@zyz.com", "name": "xyz xyz" }); test('xyz', async() => { var ProfilePic2 =require('../../src/views/ProfilePic'); const component = renderer.create( <ProfilePic/> ); expect

How to upload FormData using Axios?

纵饮孤独 提交于 2019-12-04 17:27:01
I am trying to upload 3 photos from frontend using formData. It will call an external API to make the upload. But encountered some errors as below. Frontend upload const formData = new FormData() formData.append('photoA', this.photoA) formData.append('photoB', this.photoB) formData.append('photoC', this.photoC) axios.post(`http://localhost:4172/uploadDocs`, { data: formData, accessToken: store.state.token }, { headers: { // 'Content-Type': 'Application/json', // 'x-access-token': localStorage.getItem('token') } } ).then (function (response) { return response.data }) Nodejs upload API async

Vue - Do API calls belong in Vuex?

会有一股神秘感。 提交于 2019-12-04 15:28:48
I am struggling with finding answer for where to ideally put API calls in vue modules. I am not building an SPA. For example my auth block has several components for login, password reset, account verifiction etc. Each block uses axios for API calls. Axios already provides promises, which are async. The question is about the best pracitces. Do API calls belong in a Vuex actions? Are there any pros/cons of such approach? Is there any drawback of keeping axios calls within the components they belong to? I do API calls in services, not Vuex or components. Basically, mixing the API calls in with

Post mutation to graphql with axios

ε祈祈猫儿з 提交于 2019-12-04 10:55:24
问题 This query in grahiql works: mutation { addSkill(id:"5",name:"Javascript",level:1,type:"frontend") { status id name level type } } What is the equivalent to post with axios ? I've tried this, but keep getting a 400 request response. {"errors":[{"message":"Syntax Error: Unterminated string.","locations":[{"line":3,"column":82}]}]} This is what I tried: axios .post(config.apiendpoint, { query: ` mutation addSkill($id:String!, $name:String!, $level:Float!, $type:String!) { mutation addSkill(id:

vue admin template 轻量级 后台管理系统基础模板 vuecli4 分环境打包 统一管理接口地址

扶醉桌前 提交于 2019-12-04 10:30:32
本模板目的是为了能在创建项目的时候,减少不必要的时间浪费,例如api接口的封装、axios请求的封装以及基础布局等时间的浪费,故将基础功能提取出来作为公司内部的一个后台基础管理系统,为什么不用vue-admin-template是因为有些功能并不适用于项目的需求,经过公司两个项目的经验,于是自己搭建了一款集成了element-ui的轻量级的 vue全家桶 后台管理系统基础模板,从而总结出的一套常用配置。 其中,已经配置好分环境打包、封装axios请求、统一管理接口地址,兼容ie9+、基础增删改查功能以及添加一些常用的过滤器。 如果您觉得本模板对您有帮助,请给我一个小小的star,谢谢(#^.^#) https://github.com/parchments/vue-admin-template vue版本 vue2 脚手架 vue-cli4 状态管理器 vuex UI框架 element-ui 路由 vue-router HTTP请求 axios 接口 api.js 环境 dev test uat prod 本地存储 localStorage 登录 login 动态面包屑 breadcrumb 列表展示 搜索、弹窗、分页 详情展示 路由传参 路由错误 404 兼容性 ie9及以上 时间格式化 moment 来源: https://my.oschina.net/parchments

封装axios

♀尐吖头ヾ 提交于 2019-12-04 08:33:15
1、创建一个server目录,在该目录下创建index.js文件 2、配置axios: import axios from 'axios' let loadingInstance = null //这里是loading //使用create方法创建axios实例 export const Service = axios.create({ timeout: 6000, // 请求超时时间 baseURL: process.env.BASE_API,// 配置在环境变量中 headers: { 'Content-Type': 'application/json;charset=UTF-8' } }) // 添加请求拦截器 Service.interceptors.request.use( config => { // 这里可以引入loading 或者 执行一个回调方法 return config }, error => { return Promise.reject(error) } ) // 添加响应拦截器 Service.interceptors.response.use(response => { // console.log(response) let res = response.data return res }, error => { console.log(error)