Skip to content

Instantly share code, notes, and snippets.

@joshterrill
Created September 17, 2018 06:50
Show Gist options
  • Save joshterrill/c920375bb5ac79adc8c63f282a070011 to your computer and use it in GitHub Desktop.
Save joshterrill/c920375bb5ac79adc8c63f282a070011 to your computer and use it in GitHub Desktop.
a simple Express/NodeJS REST API for verifying medical marijuana patients using the Greenlife verification system.
const express = require('express');
const request = require('request');
const app = express();
const port = process.env.PORT || 3000;
app.get('/:patientId', (req, res) => {
const options = { method: 'GET',
url: 'https://verify.greenlifemedical.com/recommendations',
qs: { utf8: '%E2%9C%93', rec_id: req.params.patientId }
};
request(options, (error, response, body) => {
if (error) throw new Error(error);
const isValid = !body.includes('No recommendation found');
res.json({isValid});
});
});
app.listen(port, () => {
console.log(`Server listening on port ${port}`);
});
@joshterrill
Copy link
Author

This is part of a full article which can be found here: https://joshterrill.com/building-an-api-for-an-app-that-doesnt-have-an-api/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment