1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

server Side REST api scripts

Discussion in 'Programming' started by rafael marques, Aug 5, 2017.

  1. #1
    Hello everyone,
    I am currently learning about React and Redux, and i would like to develop my application using these frameworks.
    However, i have a general question about the client and server interaction.

    I know that when a client requests some data, we use a GET request to call a REST api that will return some answer, which can than be rendered by the client side.

    My question now is,
    if the Rest api does not have the answer in it's database, but first needs to execute some script, like a python script, how can this be done?

    for example, imagine i have a client side which ask the user what his favorite musician is.
    Than, a Get request is made, asking that server to return some data about that musician.
    However, the database does not yet have data about that person, but first needs to execute some python script, for example, to do some webscraping first, like get a photo of that musician, or get some general info from wikipedia. Only after that script is complete, and returns some information, can the Rest api complete it's work, by returning some answer to the client side, for rendering purposes.

    I hope my question was clear enough, and that someone can help me on this.
    I appreciate your help.
     
    rafael marques, Aug 5, 2017 IP
  2. rougeceo

    rougeceo Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #2
    If you want the client making the request to wait for an external process to complete you might want to have a look at websockets https://www.websocket.org/aboutwebsocket.html

    It is basically the same thing as a rest api but the communication goes both ways so that the server can send requests back to the client.

    In this way you can send a request to the server. The server will process this request, process some external pages and data. Once the server is done the server can then tell the client that it is done finding the information and either send the information back or simply tell the client it's ok to make a new request to get the actual information.

    I have used pusher (https://pusher.com/) in the past, it's really easy to use and free. If you use a third party service you wont have to implement your own server such as redis or rabbitmq.
     
    rougeceo, Aug 10, 2017 IP