Last active
August 29, 2015 14:22
-
-
Save illbzo1/e75c503f5e0c3a9fc5ab to your computer and use it in GitHub Desktop.
An example for making POST requests to DocRaptor in Node.js, using request instead of restler
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
var request = require('request'); | |
var fs = require('fs'); | |
var content = "<html><body>TEST!</body></html>"; | |
config = { | |
url: 'https://docraptor.com/docs', | |
encoding: null, //IMPORTANT! This produces a binary body response instead of text | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
json: { | |
user_credentials: "YOUR_API_KEY_HERE", | |
doc: { | |
document_content: content, | |
name: "test.pdf", | |
document_type: "pdf", | |
test: true | |
} | |
} | |
}; | |
request.post(config, function(err, response, body) { | |
fs.writeFile('doc_raptor_sample.pdf', body, "binary", function(writeErr) { | |
console.log('Saved!'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment