Golang http write response without waiting to finish

后端 未结 3 1666
后悔当初
后悔当初 2021-01-29 08:35

I\'m building an application that builds a pdf file and returns it to the client whenever it receives a request.

Since some of these pdf files might take some time to g

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-29 09:14

    This is by no means comprehensive, but a reasonable example of how you might construct your API (which needs to be asynchronous, as the previous respondent pointed out) can be found here: https://www.adayinthelifeof.nl/2011/06/02/asynchronous-operations-in-rest/

    The job queue model is a pretty common one. I would recommend you also write a basic API binding library (you'd want this for your own testing purposes in any case) so that your users can understand how you intend them to use the API, and in writing it, you'll get a better sense of how asynchronous REST interactions feel from the end user side.

提交回复
热议问题