Reputation: 63
I send a parameter with this
apiUrl = SERVER_API_URL + '/api/import/estimatee/' + this.state.estimateId;
.post(apiUrl, formData, config)
but I need to send parameters like
apiUrl = SERVER_API_URL + '/api/import/estimatee/' + this.state.estimateId + this.state.purchaseOrder.purchaseOrderName + this.state.purchaseOrder.purchaseOrderCurr
How can I solve this Thanks for your feedback people?
Upvotes: 1
Views: 206
Reputation: 63
const { estimateId, purchaseOrderName } = this.state;
const apiUrl = `${SERVER_API_URL}/api/import/estimate/${estimateId}/${purchaseOrderName}`;
im solved this way thanks guys.
Upvotes: 0
Reputation: 19772
Use template literals
with query parameters ?
and &
to include multiple parameters:
const { estimateId, purchaseOrderCurr, purchaseOrderName } = this.state;
const apiURL = `${SERVER_API_URL}/api/import/estimate/order?estimateId=${estimateId}&purchaseOrderName=${purchaseOrderName}&purchaseOrderCurr=${purchaseOrderCurr}`
apiUrl
will now be:
http://serverapi/api/import/estimate/order?estimateId="1234"&purchaseOrderName="orderName"&purchaseOrderCurr="USD"
Then you can use axios
to post
to apiUrl
:
axios.post(apiUrl, formData, config);
OR
just paste the parameters in axios's options
-- these parameters should be appended to formData
, especially if they are relevant to what's being submitted in formData
:
const { estimateId, purchaseOrderCurr, purchaseOrderName } = this.state;
axios.post(`${SERVER_API_URL}/api/import/estimate`, { formData, estimateId, purchaseOrderCurr, purchaseOrderName }, config);
OR
const fd = new FormData();
fd.append('estimateId', estimateId);
fd.append('purchaseOrderCurr', purchaseOrderCurr);
fd.append('purchaseOrderName', purchaseOrderName);
...other formData options
axios.post(`${SERVER_API_URL}/api/import/estimate`, fd, config);
Upvotes: 2