Created
May 28, 2010 17:29
-
-
Save cmoore/417442 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- | |
CouchDB 0.11.0: | |
[error] [<0.95.0>] attempted upload of invalid JSON undefined | |
[info] [<0.95.0>] 127.0.0.1 - - 'PUT' /honks/cmoore? 400 | |
CouchDB Trunk as of 5/28 - 10:26 PST: | |
[info] [<0.95.0>] 127.0.0.1 - - 'PUT' /honks? 201 | |
[debug] [<0.114.0>] 'PUT' /honks/cmoore? {1,1} | |
Headers: [{'Connection',"keep-alive"}, | |
{'Content-Type',"application/json"}, | |
{'Host',"localhost:5984"}, | |
{'User-Agent',"hs-HTTP-4000.0.5"}] | |
[debug] [<0.114.0>] OAuth Params: [] | |
[error] [<0.114.0>] attempted upload of invalid JSON undefined | |
[info] [<0.114.0>] 127.0.0.1 - - 'PUT' /honks/cmoore? 400 | |
[debug] [<0.114.0>] httpd 400 error response: | |
{"error":"bad_request","reason":"invalid UTF-8 JSON"} | |
CouchDB rev 818083: | |
[debug] [<0.107.0>] 'PUT' /honks/cmoore? {1,1} | |
Headers: [{'Connection',"keep-alive"}, | |
{'Content-Type',"application/json"}, | |
{'Host',"localhost:5984"}, | |
{'User-Agent',"hs-HTTP-4000.0.5"}] | |
[debug] [<0.107.0>] OAuth Params: [] | |
[debug] [<0.107.0>] Minor error in HTTP request: {invalid_json,undefined} | |
[debug] [<0.107.0>] Stacktrace: [{mochijson2,decode,1}, | |
{couch_httpd_db,db_doc_req,3}, | |
{couch_httpd_db,do_db_req,2}, | |
{couch_httpd,handle_request,5}, | |
{mochiweb_http,headers,5}, | |
{proc_lib,init_p_do_apply,3}] | |
[info] [<0.107.0>] 127.0.0.1 - - 'PUT' /honks/cmoore? 500 | |
[debug] [<0.107.0>] httpd 500 error response: | |
{"error":"invalid_json","reason":"undefined"} | |
CouchDB 0.10.1 | |
[error] [<0.92.0>] attempted upload of invalid JSON undefined | |
[info] [<0.92.0>] 127.0.0.1 - - 'POST' /testify? 400 | |
-} | |
module Main where | |
import Text.JSON | |
import Database.CouchDB | |
import Database.CouchDB.JSON | |
data Person = Person { | |
name :: String, | |
email :: String | |
} deriving (Eq,Show) | |
instance JSON Person where | |
showJSON (Person nm em) = JSObject $ toJSObject [("name", showJSON nm),("email", showJSON em)] | |
readJSON val = do | |
obj <- jsonObject val | |
nm <- jsonField "name" obj | |
em <- jsonField "email" obj | |
return (Person nm em) | |
create = runCouchDB "localhost" 5984 $ createDB "honks" | |
main :: IO () | |
main = do | |
_ <- runCouchDB "localhost" 5984 $ newNamedDoc (db "honks") (doc "cmoore") $ Person "cmoore" "[email protected]" | |
putStrLn "Honk." | |
cmoore@cathedral:~/tmp$ ghci | |
GHCi, version 6.12.2: http://www.haskell.org/ghc/ :? for help | |
Loading package ghc-prim ... linking ... done. | |
Loading package integer-gmp ... linking ... done. | |
Loading package base ... linking ... done. | |
Loading package ffi-1.0 ... linking ... done. | |
Prelude> :m +Database.CouchDB | |
Prelude Database.CouchDB> :m +Text.JSON | |
Prelude Database.CouchDB Text.JSON> :set prompt "> " | |
> runCouchDB' $ createDB "testify" | |
Loading package array-0.3.0.0 ... linking ... done. | |
Loading package syb-0.1.0.2 ... linking ... done. | |
Loading package base-3.0.3.2 ... linking ... done. | |
Loading package bytestring-0.9.1.6 ... linking ... done. | |
Loading package mtl-1.1.0.2 ... linking ... done. | |
Loading package parsec-2.1.0.1 ... linking ... done. | |
Loading package network-2.2.1.5 ... linking ... done. | |
Loading package old-locale-1.0.0.2 ... linking ... done. | |
Loading package old-time-1.0.0.4 ... linking ... done. | |
Loading package HTTP-4000.0.8 ... linking ... done. | |
Loading package containers-0.3.0.0 ... linking ... done. | |
Loading package pretty-1.0.1.1 ... linking ... done. | |
Loading package json-0.4.4 ... linking ... done. | |
Loading package CouchDB-0.10.2 ... linking ... done. | |
> runCouchDB' $ newDoc (db "testify") $ JSObject $ toJSObject [("name",JSString $ toJSString $ "value")] | |
*** Exception: HTTP/1.1 400 Bad Request | |
Server: CouchDB/0.10.1 (Erlang OTP/R13B) | |
Date: Fri, 28 May 2010 18:46:36 GMT | |
Content-Type: text/plain;charset=utf-8 | |
Content-Length: 54 | |
Cache-Control: must-revalidate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment