Http 如何(异步)使用由servant';什么是气流发生器?

Http 如何(异步)使用由servant';什么是气流发生器?,http,haskell,asynchronous,servant,Http,Haskell,Asynchronous,Servant,servant文档描述了如何创建: 现在的问题是,客户机(例如用javascript编写)如何以异步方式使用端点?注意:在较新的servant(0.15IIRC)中,流媒体被重构。然而,如何使用JavaScript中的流端点的问题与后端实现无关 例如,如果使用FetchAPI,则可以使用reader API,这在中有很好的解释。总结如下: // Fetch the original image fetch('./tortoise.png') // Retrieve its body as

servant文档描述了如何创建:


现在的问题是,客户机(例如用javascript编写)如何以异步方式使用端点?

注意:在较新的
servant
0.15
IIRC)中,流媒体被重构。然而,如何使用JavaScript中的流端点的问题与后端实现无关

例如,如果使用FetchAPI,则可以使用reader API,这在中有很好的解释。总结如下:

// Fetch the original image
  fetch('./tortoise.png')
  // Retrieve its body as ReadableStream
  .then(response => {
    const reader = response.body.getReader();
然后您可以调用
reader.read()
,以获得部分响应

// Fetch the original image
  fetch('./tortoise.png')
  // Retrieve its body as ReadableStream
  .then(response => {
    const reader = response.body.getReader();