Given that you tag your question with "TCP": Usually the application just sends the data to the OS kernel using `send` or similar system calls. Delivering the data including putting the data into packets are done by the OS. The rare exceptions to this are user space TCP/IP stacks.
Note that TCP is only a byte stream and has no message semantics. Any message semantics (like request, response) are only at the application level. There is no guaranteed 1:1 relation between a single `send` and a packet on the wire, i.e. the OS is free to split a single `send` over multiple packets, combine multiple `send` in a single packet etc.