punchcard-request
v1.4.0
Published
API Request helpers for Punchcard APIs
Downloads
8
Readme
Punchcard Request
Installation
npm i punchcard-request --save
Usage
Punchcard Request can either be used to make a single request or make a collection of requests to a Punchcard API. A single request is an object with and endpoint specified, with optional configuration and API options. To make multiple requests, collect all desired single requests in to an array. Single requests return as an object
, collections of requests are returned as an array
.
const request = require('punchcard-request');
const items = [
{
get: 'all',
},
{
get: 'types',
},
];
request(items).then(results => {
console.log(results); // Array of paginated content and paginated content types available
});
Options
Endpoints
All endpoints are options of the get
parameter. Some endpoints require an additional parameter for clarity. These parameters are required.
all
- All content availabletypes
- All content types availabletype
- All content of a specific content type. Requires an additionaltype
parameter for the content typeone
- A single piece of content. Requires additionaltype
andid
properties for the content type and content ID
Configuration
punchcard
- The URL to the root of the Punchcard install. Can also be set by setting aPUNCHCARD
environment variable.
API Options
sort
- API attribute to sort on. Can be one ofid
,type
,type-slug
,key
,key-slug
. Defaults tokey
dir
sort_dir
- Sort direction, can be one ofasc
ordesc
. Defaults toasc
page
- The page to request (for pagination). Defaults to1
, starts at 1limit
per_page
- The max number of items to return per page (for pagination). Defaults to30
key
- Contentkey
that you would like to filter the request for. Only works withall
andtype
endpointsslug
key_slug
- Contentkey_slug
that you would like to filter the request for. Only works withall
andtype
endpoints