[Yesod] When POST and create new resource
Hi I have a question. I think that, when a server receive POST request and create new resource(and URI), the server response is status 201, isn't it? (I'm not really sure about this idea.) On Yesod, How we write to make status201 response?
2010/11/27 いとうかつとし <cutsea110@gmail.com>:
Hi I have a question. I think that, when a server receive POST request and create new resource(and URI), the server response is status 201, isn't it? (I'm not really sure about this idea.) On Yesod, How we write to make status201 response?
Good catch, there is not currently a way to specify arbitrary response codes in Yesod. I think two API additions are in order: * respondCreated (or some better name) which sends a 201 response. This function should take a Route master argument. * sendResponseStatus, which is like sendResponse but also takes a Status argument (Status coming from the Network.Wai module). Any thoughts? Michael
2010/11/27 Michael Snoyman <michael@snoyman.com>:
2010/11/27 いとうかつとし <cutsea110@gmail.com>:
Hi I have a question. I think that, when a server receive POST request and create new resource(and URI), the server response is status 201, isn't it? (I'm not really sure about this idea.) On Yesod, How we write to make status201 response?
Good catch, there is not currently a way to specify arbitrary response codes in Yesod. I think two API additions are in order:
* respondCreated (or some better name) which sends a 201 response. This function should take a Route master argument. * sendResponseStatus, which is like sendResponse but also takes a Status argument (Status coming from the Network.Wai module).
For all those interested, I've just pushed a commit to the repo that adds sendResponseStatus and sendResponseCreated. I *think* this is a good choice in names, and I *think* it makes sense to make sendResponseCreated its own function. However, it sort of makes sense to include Created (and 202 Accepted) as part of the Redirect family and just add appropriate constructors. On the other hand, they are *not* technically redirects... People's thoughts on this are appreciated. Michael
This might be slightly related.. in PHP code I sometimes dump something into the output stream "right now". This can be quite handy for debugging, you can tell things from the position on the page etc. Can this be done from a yesod request handler ?
It depends where you want the output to go. You can definitely add an area to your template which you can list error / debug messages. Alternatively you can do a `liftIO $ print x` from the handler function to print some output to the console (you can also liftIO other operations such as file io so you can append to a log file). there is also the onRequest function in the Yesod typeclass which gets run once per request where you can do some logging/output. -barkmadley sent from an internet enabled device 2010/11/29 Simon Michael <simon@joyful.com>:
This might be slightly related.. in PHP code I sometimes dump something into the output stream "right now". This can be quite handy for debugging, you can tell things from the position on the page etc. Can this be done from a yesod request handler ?
_______________________________________________ web-devel mailing list web-devel@haskell.org http://www.haskell.org/mailman/listinfo/web-devel
Thanks, I did not know about onRequest. I want to send debug output immediately to the response, so that it appears on the rendered web page intermixed with the regular content. Ie I'm wondering is if there's an equivalent of trace for the web output.
Once in the GWidget monad, you can use "addHtml . string": defaultLayout $ do -- stuff addHtml $ string "did stuff" -- more stuff Alternatively, you could use hamlet to put your messages into divs, so you show/hide all messages with javascript or firebug: trace :: String -> GWidget sub y () trace msg = addHamlet [$hamlet| %div!class=trace $msg$ |] Does that help? -matt On Mon, Nov 29, 2010 at 7:56 AM, Simon Michael <simon@joyful.com> wrote:
Thanks, I did not know about onRequest.
I want to send debug output immediately to the response, so that it appears on the rendered web page intermixed with the regular content. Ie I'm wondering is if there's an equivalent of trace for the web output.
_______________________________________________ web-devel mailing list web-devel@haskell.org http://www.haskell.org/mailman/listinfo/web-devel
On Mon, Nov 29, 2010 at 5:56 PM, Simon Michael <simon@joyful.com> wrote:
Thanks, I did not know about onRequest.
I want to send debug output immediately to the response, so that it appears on the rendered web page intermixed with the regular content. Ie I'm wondering is if there's an equivalent of trace for the web output.
Not really. In Yesod the entire response body is formed before being sent out, so during the "processing" phase, you can't inject information into the output stream like you can in PHP. If you're using a Hamlet template, you could stick debugging output in there, but that's probably not what you want. If you give an example of the type of debugging output you are trying to achieve, it might give some insight. Michael
participants (5)
-
Mark Bradley -
Matt Brown -
Michael Snoyman -
Simon Michael -
いとうかつとし