I currently have a flask backend and an angular frontend.
The backend database (couchdb) has a huge amount of data that needs to be dumped. For the time being, we are using a map function that call all the docs and send it as a list from the flask in a path. This is however suboptimal as this results in the server waiting until all the data is fetched (the angular currently has a Http get call which an object subscribes to)
I would like to move this to a stream where the data gets streamed to the angular front end
The backend code is fairly simple and the GET to the stream works as expected. I can call the GET using chrome or postman and i can see the data being streamed:
@app.route('/stream/', methods = ['GET'])
def streamdata():
view = db.view('_design/dd/_view/viewdocument')
def generate():
for row in [x['value'] for x in view.rows]]:
yield json.dumps(row)
return Response(generate(), mimetype = 'application/json')
My question is how do I get this stream in the front end? A standard http call (and then assigning an array to the object) does not seem to work
for instance, I tried defining a function in the service that catches the stream:
getstream = () => {
this.http.get<any>('http://localhost:5007/stream/').pipe(
map(response => data, error => console.log(error)))
}
I then tried to created a variable that subscribed to to object in the front end. But this does not seem to work
Any help is appreciated.
Regards, Galeej
map(response => datawhere data id defined? it suppose tomap(response => responseand in component you should get in observable i.edata$ = this.service.getstream()