How to send form data with Get method in axios? - axios

I want to call an api with GET method and pass some form data. But seem axios is not supporting the form data with GET. Is there any way for me to overcome this problem?
ps: I am using react query and axios

You can't send a form data through GET request but you can customize the request's URL query parameters. Look at the code sample below.
//assuming instance is your axios instance.
instance.get("/test",{params:{key:value, key1:value1}}).then((data)=>{}).catch((error)=>{})
//this will send a GET request to /test?key=value&key1=value1
GET request doesn't support form data but you can use URL query parameters. Just like I did above.
For more information about axios visit axios npm package

Related

How to solve Get request and axios error?

I have used Axios for fetching my data to client side from my API but my Get request didn't work well and axios shows some error.
Here i add my code and problem as Screenshot..

How to send user input from TextField to GET method API without body? - Dart

I have a feedback form like this
the API for it using a GET method without body. I have to send user input from the 3 TextField (Nama, Email, Pesan Anda) to GET method API.
I'm clueless, my senior said that I have to use url parameters so I can still send data to API without a body.
How can I do that?
HTTP GET method has no body on it's requisitions, so yes, the only way to send params is in the url, where you can send like this:
http://{URL}/?nama=Nama&email=Email&pesanAnda=PesanAnda
then you API will have access to these params.

how to make a get request to data from response_url of slack api

I am using the slack api in a typescript application, where when I initially send a payload through a slack / command, this payload has a response_url. I am able to post data to this response_url with axios, but I have trouble making a get request to this url to access the data I have previously posted. I have tried axios.get(response_url) and await axios.get(response_url) but I have gotten invoke error with status code 500 and a result of Promise {<pending>} - would anyone know the correct way to use the get call?

How to remove HTML content from REST API response?

I have started to work with REST APIs - specifically JIRA REST APIs.
I'm using the API to get response to a JIRA query but the JSON response I am getting contains lot of HTML chunk inside it.
It is not clean enough as showcased here
How can I use it in such a way to get a proper JSON response?
I think, JIRA response in JSON format only if request is successful, if request has any error than it comes in HTML response. actually that html belongs to the JIRA's error page. So correct your request, you will not get any response in HTML fomat. :)

Zend Based REST URI for POST and PUT methods

This post if a follow-up question to mt previous post:
Android RESTful Web application using Zend Framework
I have written a web application which is based on the Zend Framework (Version 1.11.11) and I want to use the SAME backend code for coding the mobile version of this application (Android). To achieve this, I want to get the response for each of the actions in the controllers in XML and JSON - for mobile-based app.
Using the answers provided in the above link, I am able to get the XML and JSON response by making use of the AjaxContext helper. I set the contexts as json for the required actions in the init method and I am getting the desired json response.
Now I have another challenge. How to know from the URL if the given action was a GET or a POST request? Do I have have to add that as a query parameter? Is that the correct way?
For example, for login action within User controller: URL will be: [link] (http://localhost/user/login)
But within the loginAction, I check if the given request if a post and authenticate only if the request is a post. So the URL: http://localhost/user/login?format=xml will always return to me the response for a GET request since there is no way of knowing if the request was a GET or POST. Please help.
Thanks.
Abhilash
like you added format parameter do the same for request . Use "method" parameter to decide what type of request is it . Or you can also do is
$this->getRequest()->isPost(); //create
$this->getRequest()->isGet(); //read
$this->getRequest()->isPut(); // update
$this->getRequest()->isDelete(); // delete