...
Please improve the code examples and extend this page to cover additional languages and use cases.
Python
Python module for Okapi queries
Members of EBSCO's FSE team have published a python module for FOLIO - https://pypi.org/project/folioclient/ - that is a wrapper around common API calls.
Jupyter Notebooks
Jupyter Notebooks (https://jupyter.org/) are common, user-friendly tools that community members are learning to use to query FOLIO for data.
The advantage of Jupyter Notebooks is that you don't have to install anything on your computer to write programs, they are easy to publish and share, and their format makes it intuitive to document what you are doing as you go.
An example notebook has been shared by Lisa Sjögren (EBSCO) - https://colab.research.google.com/drive/12geGqqIEfLsEpxYlnt6m0M7ARQG64jIH?usp=sharing - this example is published on Google's Colaboratory platform, which is based on Jupyter Notebooks (https://colab.research.google.com/).
Perl
Use the LWP::UserAgent module to simplify REST calls:
...
Code Block | ||||
---|---|---|---|---|
| ||||
const https = require('https'); function getPromise_token() { return new Promise(( resolve, reject ) => { if ( x_okapi_token == '' ) { const data = JSON.stringify ({ username: 'diku_admin', password: 'admin' }); const options = { hostname: 'folio-snapshot-okapi.dev.folio.org', port: '443', path: '/authn/login', method: 'POST', headers: { 'Content-type': 'application/json', 'Content-Length': data.length, 'x-okapi-tenant': 'diku', 'x-okapi-token': '' } } const req = https.request(options, res => { res.on('data', d => { process.stdout.write(d); }) x_okapi_token = res.headers['x-okapi-token']; resolve(x_okapi_token); }) req.on('error', error => { reject(error); }) req.write(data); req.end(); } else { resolve(x_okapi_token); } }); } async function get_token() { try { let http_promise = getPromise_token(); let x_okapi_token = await http_promise; return x_okapi_token; } catch(error) { console.log(error); } } |