PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, October 13, 2022

[FIXED] How to change post request to get request in postman?

 October 13, 2022     axios, javascript     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing