Created
September 17, 2018 06:50
-
-
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.
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
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}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/