Created
November 16, 2017 17:26
-
-
Save emilyruby/156bc533feb0ee05f909a21ff828cf5d to your computer and use it in GitHub Desktop.
This file contains 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 algoliasearch = require('algoliasearch') | |
const express = require('express') | |
const bodyParser = require('body-parser') | |
const app = express() | |
const client = algoliasearch('H1LZZCXWZT', process.env.API_KEY) | |
const index = client.initIndex('movies') | |
app.get('/', (req, res) => res.send('GET')) | |
app.post('/api/1/movies', bodyParser.json(), async (req, res) => { | |
if (req.body) { | |
try { | |
const content = await index.addObjects([req.body]) | |
res.send(content.objectIDs[0]) | |
} catch (e) { | |
console.error(e) | |
res.status(500).send('ERROR') | |
} | |
} | |
}) | |
app.delete('/api/1/movies/:id', async (req, res) => { | |
try { | |
const result = await index.deleteObject(req.params.id) | |
res.send(result.objectID) | |
} catch (e) { | |
console.error(e) | |
res.status(500).send('ERROR') | |
} | |
res.send('DELETE') | |
}) | |
app.listen(9000, () => console.log('Example app is listening on port 9000!')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment