Created
March 5, 2018 02:44
-
-
Save andrewmartin/db8fed065a1ed5d6276f5f444c1d1afa to your computer and use it in GitHub Desktop.
contentful-api-endpoint-node
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 contentful = require('contentful'); | |
const client = contentful.createClient({ | |
space: '<space_id>', | |
accessToken: '<access_token>', | |
}); | |
export default (req, res) => { | |
return client.getEntry({ | |
content_type: 'page', | |
'fields.title': req.params.title, | |
}) | |
.then((entry) => { | |
return res.json(entry); | |
}) | |
.catch(error => { | |
return res | |
.status(400) | |
.json({ | |
error: error.response.data, | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment