Closed G07cha closed 8 years ago
Which properties do you have in mind? Through HTTP you can send both headers with res.setHeader("X-Foo", "123")
or body, with res.write
.
@moll I would like to send something like {"foo": "bar"} in body, but as I know res.write
allow only string
or buffer
argument types.
Yep. That's because HTTP, the underlying protocol, is text based.
You'll have to do this:
res.setHeader("Content-Type", "application/json")
res.end(JSON.stringify({name: "John"}))
I don't know what's the best resource for reading more about HTTP and its idioms, but perhaps you're better at finding that out. ;)
Thank you a lot, it's shame for me to don't know such fundamentals, I'm try to correct this as soon as possible, thanks again!
You're welcome.
I can't find how to set custom body for http response, for example if use
res.write
orres.end
functions it will set only message property, how do I define other response properties?