0

This is my postman request:

http/localhost:8080/sample-market/marketAPI/1234/product/publish?productOne=testing&productTwo=checking 

Can anyone help me with how to do a post call through axios. productOne & productTwo are query param & 1234 is path parameter

2

1 Answer 1

2

I think you should read the DOC first:

From : https://www.npmjs.com/package/axios

Your given URL looks like get method:

http/localhost:8080/sample-market/marketAPI/1234/product/publish?productOne=testing&productTwo=checking 

But if you still want to use POST, then here you go :

axios.post('http/localhost:8080/sample-market/marketAPI/1234/product/publish', { productOne: 'testing', productTwo: 'checking' }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }); 

For GET method :

axios.get('http/localhost:8080/sample-market/marketAPI/1234/product/publish', { params: { productOne: 'testing', productTwo: 'checking' } }) //OR direct axios.get('http/localhost:8080/sample-market/marketAPI/1234/product/publish?productOne=testing&productTwo=checking') 
Sign up to request clarification or add additional context in comments.

7 Comments

So why post an answer then?
updating as per url, so he can get idea, nothing else
yes its completely fine to have a post call without any body
@Singh, in that case, you should use GET method, POST word is for that means you are about to post , and GET is for to get data
ok can you plz explain me , what is the need of query param? i have given an API which has query param and its a post call! that post has an empty body with the two query params
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.