Last active
August 29, 2015 14:03
-
-
Save m1kc/9a156f56ac96d6ca5c51 to your computer and use it in GitHub Desktop.
Посвящается тем говноедам, которые не любят CoffeeScript.
This file contains 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
request = require 'request' | |
rand = Math.floor(Math.random()*100000000).toString() | |
request( | |
method: 'PUT' | |
uri: 'http://mikeal.iriscouch.com/testjs/' + rand | |
multipart: [ | |
'content-type': 'application/json' | |
'body': JSON.stringify( | |
foo: 'bar' | |
_attachments: | |
'message.txt': | |
follows: true | |
length: 18 | |
'content_type': 'text/plain' | |
) | |
, | |
body: 'I am an attachment' | |
] | |
, | |
(error, response, body) -> | |
if response.statusCode is 201 | |
console.log "document saved as: http://mikeal.iriscouch.com/testjs/#{rand}" | |
else | |
console.log "error: #{response.statusCode}" | |
console.log body | |
) |
This file contains 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
var request = require('request') | |
, rand = Math.floor(Math.random()*100000000).toString() | |
; | |
request( | |
{ method: 'PUT' | |
, uri: 'http://mikeal.iriscouch.com/testjs/' + rand | |
, multipart: | |
[ { 'content-type': 'application/json' | |
, body: JSON.stringify({ | |
foo: 'bar' | |
, _attachments: { | |
'message.txt': { | |
follows: true | |
, length: 18 | |
, 'content_type': 'text/plain' | |
} | |
} | |
}) | |
} | |
, { body: 'I am an attachment' } | |
] | |
} | |
, function (error, response, body) { | |
if(response.statusCode == 201){ | |
console.log('document saved as: http://mikeal.iriscouch.com/testjs/'+ rand) | |
} else { | |
console.log('error: '+ response.statusCode) | |
console.log(body) | |
} | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment