Issue
I have a request and it was post request earlier but I need to change it to get request.
//teamsApi.js
async getTeamsWithPlayers(payload) {
const response = await this.request('/teams/getPlayers', payload) //post request
return response
}
//base.js
import {$api_esports} from '../api'
export class API_BASE_ESPORTS {
async request(url, payload, config) {
const response = await $api_esports.post(url, payload, config).then(handleData).catch(handleError)
return response
}
}
//api.js
export const $api_esports = axios.create({
withCredentials: false,
baseURL: API_ESPORT_URL,
})
I tried to add new request to API_BASE_ESPORTS but it didn't work(like this)
export class API_BASE_ESPORTS {
async request(url, payload, config) {
const response = await $api_esports.post(url, payload, config).then(handleData).catch(handleError)
return response
}
async getRequest(url) {
const response = await $api_esports.get(url).then(handleData).catch(handleError)
return response
}
}
Solution
If I haven't overlooked something, axios doesn't allow GET requests with additional payload:
https://github.com/axios/axios#request-config (see the data
property).
This means, you'd have to convert your payload into a URL parameter string, append that to the URL you pass to API_BASE_ESPORTS.request
and additionally change the $api_esports.post
call to $api_esports.get
.
Answered By - David Answer Checked By - Pedro (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.