B
B
beduin012018-05-02 20:40:05
Python
beduin01, 2018-05-02 20:40:05

Why is the response type passed to the method as a variable?

Most web frameworks use the following construct: It's not clear why resp is always passed into the handler function. It's the same answer. We do not accept it, but must return it.
def on_get(self, req, resp):

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Kitaev, 2018-05-02
@beduin01

So that you do not copy-paste the response constructor everywhere, a blank is passed. And yes, not "in the majority", but in asynchronous / non-blocking ones, because in synchronous response classes are primitive and are used only after the response is completed.

P
Pavlo Ponomarenko, 2018-05-02
@TheShock

This is the object that you must complete. In functional languages, this could well be a return value, but it is difficult to pass it to another asynchronous function. Synthetic example:
From the less synthetic examples, the need to make an asynchronous request in order to eventually form a response

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question