NodeJS + Prepr CMS

This is the official Prepr SDK for Node.js. It provided a standardized way
for your team to communicate with Prepr.

Install

Get started by installing the SDK in your application, simply open a terminal and enter

npm i @preprio/nodejs-sdk

Set up a client

We don't want to repeat configuration for every API call, that's why we suggest you create a client from which you make requests. Let's make a client by creating services/prepr.js with the following code.

// services/prepr.js

const { createPreprClient } = require('@preprio/nodejs-sdk')

const prepr = createPreprClient({
    token: '<YourAccessToken>', // You can find one in your Prepr environment
    baseUrl: 'https://graphql.prepr.io/graphql',
    userId: null, // Optional, used for AB testing implmentations
})

module.exports = { prepr }

Great, now we have the configuration in one place. Now, we can import our configured Prepr client to perform requests.

Query the API

To perform requests you can make use of our fluent builder, this is how it looks like

    // We created this earlier
    const {prepr} = require('./services/prepr')
    
    const result = await prepr
        .graphqlQuery(`{
            BlogPosts {
                items {
                    _id
                    title
                    summary
                    _read_time
                }
            }
        }`)
        .fetch();

Let's request all Pages in our Prepr environment.

    // We created this earlier
    const {prepr} = require('./services/prepr')
    
    const result = await prepr
        .graphqlQuery(`{
            Pages {
                items {
                    _id
                    title
                    summary
                }
            }
        }`)
        .fetch();

To help you querying our API we've added multiple examples in the GraphQL section.

Reach out to us

You have questions about how to use this library?
Contact our support team at [email protected] or join us on Slack.

You found a bug or want to propose a feature?
File an issue here on GitHub. Don't share any authentication info in any code before sharing it.