Skip to content

Instantly share code, notes, and snippets.

@m1kc
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m1kc/9a156f56ac96d6ca5c51 to your computer and use it in GitHub Desktop.
Save m1kc/9a156f56ac96d6ca5c51 to your computer and use it in GitHub Desktop.
Посвящается тем говноедам, которые не любят CoffeeScript.
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
)
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