0.1.17 • Published 7 months ago

@webcontext/contentful v0.1.17

Weekly downloads
-
License
-
Repository
github
Last release
7 months ago

Documentation Guide: Running the Contentful API for Webcontext Users

This guide provides instructions on how to install, use, and run the @webcontext/contentful package, which provides a convenient way to fetch data from the Contentful API for Webcontext users.

1. Installation

To get started, install the package using Yarn. In your project directory, run the following command:

yarn add "@webcontext/contentful"

2. Usage

Once the package is installed, you can use it to fetch data from Contentful. Here’s how to use the contentfulDelivery function.

2.1 Basic Usage

In your code, import the contentfulDelivery function from the package:

import { contentfulDelivery } from '@webcontext/contentful';

2.2 Fetching Data by Predefined Query (From File)

If you have a predefined query in a local file, you can use it as follows:

// Fetch data using a predefined query (e.g., 'copy-club') from a local file
const data = await contentfulDelivery({
  query: 'copy-club', // Name of the predefined query
  fromFile: true, // Indicates the query is from a local file
  fnSring: 'getEntries', // Optional function, defaults to 'getEntries'
});
console.log(data);

In this example, the query copy-club refers to a predefined query stored locally. The second property, fromFile: true, ensures the function reads from a file, while fnSring specifies the function to call (optional and defaults to getEntries).

2.3 Fetching Data with a Custom Query

For more flexible data retrieval, you can provide a custom query object:

const query = {
  query: {
    content_type: 'category', // The content type to retrieve, mandatory
    select: 'fields.name', // Optional: Specify fields to select
  },
  fromFile: false, // Indicates it's a custom query, not from a file
  fnSring: 'getEntries', // Optional, defaults to 'getEntries'
};

const data = await contentfulDelivery(query);
console.log(data);

In this example, a custom query is sent directly to the Contentful API, retrieving only the fields specified in the query.

3. Predefined Queries

The current predefined query list includes:

  • copy-club

You can use these predefined queries by passing the query name in the query field and setting fromFile to true.

4. Examples

Example 1: Using a Predefined Query (From File)

import { contentfulDelivery } from '@webcontext/contentful';

const data = await contentfulDelivery({
  query: 'copy-club',
  fromFile: true,
});
console.log(data);

Example 2: Using a Custom Query

import { contentfulDelivery } from '@webcontext/contentful';

const query = {
  query: {
    content_type: 'category',
    select: 'fields.name', // Optional field selector
  },
  fromFile: false, // Indicates custom query
  fnSring: 'getEntries', // Optional, defaults to 'getEntries'
};

const data = await contentfulDelivery(query);
console.log(data);

5. Conclusion

The@webcontext/contentful package simplifies interaction with the Contentful Delivery API. You can either use predefined queries stored locally or construct custom queries for flexible data retrieval from Contentful. Make sure your queries adhere to (https://www.contentful.com/developers/docs/references/content-delivery-api/)Contentful's API documentation.

0.1.17

7 months ago

0.1.16

7 months ago

0.1.15

7 months ago

0.1.14

7 months ago

0.1.13

7 months ago

0.1.12

7 months ago

0.1.11

7 months ago

0.1.10

7 months ago

0.1.9

7 months ago

0.1.8

7 months ago

0.1.7

7 months ago

0.1.6

7 months ago

0.1.5

7 months ago

0.1.4

7 months ago

0.1.3

7 months ago

0.1.2

7 months ago

0.1.1

7 months ago

0.1.0

8 months ago