Created
May 8, 2018 19:51
-
-
Save christineywang/e0bf9fb8cd09dd7f75e5c7a74937a402 to your computer and use it in GitHub Desktop.
Performance test by Tom
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
// Here we're requiring the contentful SDK module in order to use it later | |
const contentful = require('contentful'); | |
// The SDK requires us to define a client which then provides all the functionalities from https://www.contentful.com/developers/docs/references/content-delivery-api/. Make sure to replace the space ID and CDA token as required. | |
const client = contentful.createClient({ | |
space: '<spaceID>', | |
accessToken: '<token>', | |
// host: 'preview.contentful.com', | |
}) | |
// We're storing the start time in a variable called 'start' | |
var start = new Date().getTime(); | |
// Now it's time to do something with the SDK. You can find all the functionalites in our API reference, including example code (e.g. https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/select-operator/query-entries/console/js). The below code for example fetches entries of a specified content type for a given locale, uses the select operator to define some fields we're retrieving and makes sure we get the maximum amount of entries possible (1,000). | |
client.getEntries({ | |
//content_type: 'blogPost', | |
//locale: 'en-US', | |
//select: 'fields.title,fields.slug,fields.body,sys', | |
limit: 1000 | |
}) | |
.then((response) => { | |
// Once we have a response, we store the end time in a variable called 'end'... | |
var end = new Date().getTime(); | |
// ...and then calculate the difference between 'start' and 'end' | |
var time = end - start; | |
// Finally, we log the result | |
console.log('Fetched ' + response.items.length + ' items in ' + time + ' ms'); | |
}) | |
// This is just in case any errors occur (but we aren't really handling them as this is just to measure the performance) | |
.catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment