M
M
Maxim Korolsky2016-05-11 22:54:47
JavaScript
Maxim Korolsky, 2016-05-11 22:54:47

How to send an image to an API using React-Router and get a response?

They gave me an API, this is the url:
api/upload
I need to send a picture to this API, receive a response and work with the response already
. Tell me how to do it correctly
. Is something like a request-promise package suitable for this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2016-05-11
@maxfarseer

Since I see redux in the tags, I will answer "within the framework" of this project.
You need to use action (action) - "Sending_image" (and this is a normal asynchronous request, most likely a POST request, right?)
And then in response to your asynchronous request, emit an event "Image_sent" + response data.
In the reducer, you catch the "image sent" event and add the received data to the store.
And here the router is unclear. Routing is not working with "urls" at all. It's just part of the job, so to speak. Roughly speaking, the react-router decides, based on the url-address, which component(s) to show you.
You can read about working with asynchronous actions in redux here .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question