{"id":2792,"date":"2013-10-09T10:37:31","date_gmt":"2013-10-09T01:37:31","guid":{"rendered":"http:\/\/www.techscore.com\/blog\/?p=2792"},"modified":"2018-11-14T16:33:53","modified_gmt":"2018-11-14T07:33:53","slug":"yesod%e5%85%a5%e9%96%80-5-handler-%e3%83%ac%e3%82%b9%e3%83%9d%e3%83%b3%e3%82%b9%e3%82%92%e8%bf%94%e3%81%99%e3%81%9f%e3%82%81%e3%81%ae%e9%96%a2%e6%95%b0","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2013\/10\/09\/yesod%e5%85%a5%e9%96%80-5-handler-%e3%83%ac%e3%82%b9%e3%83%9d%e3%83%b3%e3%82%b9%e3%82%92%e8%bf%94%e3%81%99%e3%81%9f%e3%82%81%e3%81%ae%e9%96%a2%e6%95%b0\/","title":{"rendered":"Yesod\u5165\u9580 (5) Handler: \u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u8fd4\u3059\u305f\u3081\u306e\u95a2\u6570"},"content":{"rendered":"

\u3053\u3093\u306b\u3061\u306f\u3001\u9234\u6728\u3067\u3059\u3002<\/p>\n

Handler \u3067\u4f7f\u7528\u3059\u308b\u3001\u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u8fd4\u3059\u305f\u3081\u306e\u95a2\u6570\u3092\u8abf\u3079\u305f\u306e\u3067\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n

 <\/p>\n

\u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u8fd4\u3059\u305f\u3081\u306e\u95a2\u6570<\/h2>\n

\u666e\u901a\u306e\u30da\u30fc\u30b8\u3067\u3042\u308c\u3070\u300c\u30ea\u30af\u30a8\u30b9\u30c8 \u2192 Hadler \u3067\u51e6\u7406\u3059\u308b \u2192 \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u304c\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\u3055\u308c\u308b \u2192 \u30ec\u30b9\u30dd\u30f3\u30b9\u3068\u3057\u3066\u8fd4\u3055\u308c\u3066 200 OK!\u300d\u3068\u3044\u3046\u9806\u756a\u3067\u51e6\u7406\u3055\u308c\u307e\u3059\u304c\u3001Yesod \u306b\u306f\u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u8fd4\u3059\u305f\u3081\u306e\u4fbf\u5229\u306a\u95a2\u6570\u304c\u3044\u304f\u3064\u304b\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n

sendResponse<\/h3>\n

\u300c200 OK\u300d\u3092\u8fd4\u3059\u95a2\u6570\u3067\u3059\u3002<\/p>\n

-- \u672c\u6587\u304c\u7a7a\u306e\u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u8fd4\u3059.\r\ngetHomeR = sendResponse (typePlain, emptyContent)\r\n\r\n-- \u30c6\u30ad\u30b9\u30c8\u3067\u300cOK\u300d\u3092\u8fd4\u3059.\r\ngetHomeR = sendResponse $ toTypedContent (\"OK\" :: Text)<\/pre>\n

typePlain \u306f\u300cContent-Type: text\/plain\u300d\u3092\u8868\u3059\u3082\u306e\u3067\u3001\u4ed6\u306b\u3082 typeHtml \u3084 typeJson, typePng \u306a\u3069\u304c\u300cyesod-core\/Yesod\/Core\/Content.hs<\/a>\u300d\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n

toTypedContent \u3092\u4f7f\u3046\u3053\u3068\u3067\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u8fd4\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u52d5\u7684\u306b\u751f\u6210\u3057\u305f\u30b3\u30f3\u30c6\u30f3\u30c4\uff08\u753b\u50cf\u306a\u3069\uff09\u3092\u8fd4\u3057\u305f\u3044\u5834\u5408\u306b\u6d3b\u7528\u3067\u304d\u305d\u3046\u3067\u3059\u3002<\/p>\n

sendResponseCreated<\/h3>\n

\u300c201 Created\u300d\u3092\u8fd4\u3059\u95a2\u6570\u3067\u3059\u3002<\/p>\n

getHomeR = sendResponseCreated HelloR<\/pre>\n

\u5f15\u6570\u306b HelloR \u3092\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u3053\u308c\u306f\u30ec\u30b9\u30dd\u30f3\u30b9\u306e Location \u30d8\u30c3\u30c0\u3067\u6307\u5b9a\u3055\u308c\u308b URL \u306b\u5bfe\u5fdc\u3057\u307e\u3059\u3002<\/p>\n

redirect<\/h3>\n

\u540d\u524d\u306e\u901a\u308a\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3092\u884c\u3046\u95a2\u6570\u3067\u3059\u3002<\/p>\n

Yesod \u306e\u30b5\u30a4\u30c8\u306b\u306f\u300c\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304c HTTP\/1.1 \u306e\u5834\u5408\u306f 303 See Other \u3092\u8fd4\u3057\u3001HTTP\/1.0 \u306e\u5834\u5408\u306f 302 Found \u3092\u8fd4\u3059\u300d\u3068\u66f8\u304b\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u5b9f\u969b\u306b\u8a66\u3057\u305f\u3068\u3053\u308d\u3001\u3069\u3061\u3089\u3067\u3082\u300c303 See Other\u300d\u304c\u8fd4\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n

getHomeR 300 = redirect HelloR\r\n\r\n-- \u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u6307\u5b9a\u3059\u308b\u5834\u5408.\r\ngetHomeR 301 = redirect (HelloR, [(\"message\", \"hello\")])<\/pre>\n

invalidArgs<\/h3>\n

\u300c400 Bad Request\u300d\u3092\u8fd4\u3059\u95a2\u6570\u3067\u3059\u3002<\/p>\n

getHomeR 400 = invalidArgs [\"\u7121\u52b9\u306a\u30ea\u30af\u30a8\u30b9\u30c8\u3067\u3059\", \"\u6b63\u3057\u3044\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u6307\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\"]<\/pre>\n

\u5f15\u6570\u306b\u306f\u30ea\u30b9\u30c8\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u8907\u6570\u306e\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u6307\u5b9a\u3059\u308b\u305f\u3081\u306b\u3001\u3053\u306e\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n

notAuthenticated<\/h3>\n

\u300c401 Unauthorized\u300d\u3092\u8fd4\u3059\u95a2\u6570\u3067\u3059\u3002<\/p>\n

getHomeR = notAuthenticated<\/pre>\n

permissionDenied<\/h3>\n

\u300c403 Forbidden\u300d\u3092\u8fd4\u3059\u95a2\u6570\u3067\u3059\u3002<\/p>\n

getHomeR 403 = permissionDenied \"\u898b\u305b\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\"<\/pre>\n

notFound<\/h3>\n

\u300c404 Not Found\u300d\u3092\u8fd4\u3059\u95a2\u6570\u3067\u3059\u3002<\/p>\n

getHomeR = notFound<\/pre>\n

\u00a0badMethod<\/strong><\/h3>\n

\u300c405 Method Not Allowed\u300d\u3092\u8fd4\u3059\u95a2\u6570\u3067\u3059\u3002<\/p>\n

getHomeR = badMethod<\/pre>\n

sendFile<\/h3>\n

\u30d5\u30a1\u30a4\u30eb\u3092\u305d\u306e\u307e\u307e\u8fd4\u3059\u5834\u5408\u306b\u4f7f\u7528\u3059\u308b\u95a2\u6570\u3067\u3059\u3002<\/p>\n

getHomeR = sendFile \"text\/plain\" \"static\/your-file.txt\"<\/pre>\n

\u6700\u521d\u306e\u5f15\u6570\u306b\u306f Content-Type \u3092\u6307\u5b9a\u3057\u3001\u4e8c\u756a\u76ee\u306e\u5f15\u6570\u306b\u306f\u30d5\u30a1\u30a4\u30eb\u306e\u30d1\u30b9\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n

addHeader<\/h3>\n

\u30ec\u30b9\u30dd\u30f3\u30b9\u30d8\u30c3\u30c0\u3092\u8ffd\u52a0\u3059\u308b\u95a2\u6570\u3067\u3059\u3002<\/p>\n

\u203b\u4ee5\u524d\u306f setHeader \u3068\u3044\u3046\u540d\u524d\u3067\u3057\u305f\u304c\u30011.2 \u304b\u3089 addHeader \u306b\u5909\u66f4\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n

addHeader \"X-Hoge\" \"hoge\"<\/pre>\n

 <\/p>\n

\u307e\u3068\u3081<\/h2>\n

\u4eca\u56de\u306f Handler \u3067\u4f7f\u7528\u3059\u308b\u3001\u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u8fd4\u3059\u305f\u3081\u306e\u95a2\u6570\u3092\u8abf\u3079\u307e\u3057\u305f\u3002<\/p>\n

Yesod \u306e\u30b5\u30a4\u30c8\u306b\u3042\u308b\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306b\u306f\u95a2\u6570\u540d\u306f\u66f8\u304b\u308c\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u5f15\u6570\u304c\u4f55\u304b\u307e\u3067\u306f\u66f8\u304b\u308c\u3066\u3044\u306a\u304b\u3063\u305f\u306e\u3067\u82e6\u52b4\u3057\u307e\u3057\u305f\u3002<\/p>\n

 <\/p>\n","protected":false},"excerpt":{"rendered":"

\u3053\u3093\u306b\u3061\u306f\u3001\u9234\u6728\u3067\u3059\u3002<\/p>\n

Handler \u3067\u4f7f\u7528\u3059\u308b\u3001\u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u8fd4\u3059\u305f\u3081\u306e\u95a2\u6570\u3092\u8abf\u3079\u305f\u306e\u3067\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002
\u7d9a\u304d\u3092\u8aad\u3080...<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[102,18,84],"tags":[99,100],"_links":{"self":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/2792"}],"collection":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/comments?post=2792"}],"version-history":[{"count":1,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/2792\/revisions"}],"predecessor-version":[{"id":17908,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/2792\/revisions\/17908"}],"wp:attachment":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/media?parent=2792"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/categories?post=2792"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/tags?post=2792"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}