Giter VIP home page Giter VIP logo

node-cloudflare's Introduction

NPM version Downloads

CloudFlare API v4

The Cloudflare4 module allows you to communicate with the CloudFlare V4 API from node.js in a promise friendly manner.

It also supports automatic request retries.

Installation

This module is published in NPM:

npm install cloudflare4 --save

The --save tells NPM to automatically add it to your package.json file

Usage

// Import a module
var CloudFlareAPI = require('cloudflare4');

// Create an instance with your API V4 credentials
var api = new CloudFlareAPI({email: '[email protected]', key: 'my_key'});

// Get things done
api.userFirewallAccessRuleGetAll().then(function (rules) {
	console.log(rules);
});

Config

new CloudFlareAPI({
	email: '[email protected]',
	key: 'my_key',
	itemsPerPage: 100, // default=100
	maxRetries: 5, // default=5
	raw: false // default=false,
	autoPagination: false, // default=false
	autoPaginationConcurrency: 1 // default=1
});

Pagination

you can pass pagination params into any method that has a body or query argument.

api.userFirewallAccessRuleGetAll({per_page: 1, page: 2}).then(function (rules) {
	console.log(rules);
});

or with auto-pagination

api.userFirewallAccessRuleGetAll({auto_pagination: true, auto_pagination_concurrency: 1}).then(function (rules) {
	console.log(rules);
});

Note: if you use auto_pagination for a GetAll the raw argument is no longer respected

Raw

if you set raw it will return the full response body including pagination details

api.userGet(true)

would return

{
	result: { 
		id: 'dc19c3231tds452eb4ebc123d6eb4c99',
		email: '[email protected]',
		username: 'username',
		first_name: 'Foo',
		last_name: 'Bar',
		telephone: '5555555555',
		country: null,
		zipcode: null,
		two_factor_authentication_enabled: false,
		two_factor_authentication_locked: false,
		created_on: '2014-09-29T13:21:56.807670Z',
		modified_on: '2015-10-04T00:02:50.855108Z',
		organizations: null,
		has_pro_zones: true,
		has_business_zones: false,
		has_enterprise_zones: false
	},
	success: true,
	errors: [],
	messages: []
}

and with raw set to false (the default), it would return

{ 
	id: 'dc19c3231tds452eb4ebc123d6eb4c99',
	email: '[email protected]',
	username: 'username',
	first_name: 'Foo',
	last_name: 'Bar',
	telephone: '5555555555',
	country: null,
	zipcode: null,
	two_factor_authentication_enabled: false,
	two_factor_authentication_locked: false,
	created_on: '2014-09-29T13:21:56.807670Z',
	modified_on: '2015-10-04T00:02:50.855108Z',
	organizations: null,
	has_pro_zones: true,
	has_business_zones: false,
	has_enterprise_zones: false
}

Debugging

we use the debug module so you can debug the http requests by doing the following

DEBUG=http node myfile.js

also all methods enforce type checking so invalid usage would result in errors like this

Debug Example

Methods

All methods follow the official API documentation.

node-cloudflare's People

Contributors

icodeforlove avatar bob6664569 avatar mayo avatar

Watchers

James Cloos avatar Marcus avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.