Created
February 24, 2017 15:31
-
-
Save blokhin/fedfe8a7c5fb4a771115322ce2dd39ab 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
| #!/usr/bin/env node | |
| var https = require('https'); | |
| var qs = require('querystring'); | |
| var api_key = ""; // your key | |
| var host = "api.mpds.io", port = 443, path = "/v0/download/facet"; | |
| var search = { | |
| "elements": "Mn", | |
| "classes": "binary, oxide", | |
| "props": "isothermal bulk modulus", // see https://mpds.io/#hierarchy | |
| "lattices": "cubic" | |
| }; | |
| https.request({ | |
| host: host, | |
| port: port, | |
| path: path + '?' + qs.stringify({q: JSON.stringify(search), pagesize: 10}), | |
| method: 'GET', | |
| headers: {'Key': api_key} | |
| }, function(response){ | |
| var result = ''; | |
| if (response.statusCode != 200){ | |
| // NB 400 means wrong input, 403 means authorization issue etc. | |
| // see https://en.wikipedia.org/wiki/List_of_HTTP_status_codes | |
| return console.error('Error code: ' + response.statusCode); | |
| } | |
| response.on('data', function(chunk){ | |
| result += chunk; | |
| }); | |
| response.on('end', function(){ | |
| result = JSON.parse(result); | |
| if (result.error) console.error(result.error); | |
| else { | |
| console.log('OK, got ' + result.out.length + ' hits'); | |
| } | |
| }); | |
| }).on('error', function(err){ | |
| console.error('Network error: ' + err); | |
| }).end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment