wpapi.js
function WPAPI( options ) {

	// Enforce `new`
	if ( this instanceof WPAPI === false ) {
		return new WPAPI( options );
	}

	if ( typeof options.endpoint !== 'string' ) {
		throw new Error( 'options hash must contain an API endpoint URL string' );
	}

	// Dictionary to be filled by handlers for default namespaces
	this._ns = {};

	this._options = {
		// Ensure trailing slash on endpoint URI
		endpoint: options.endpoint.replace(  /\/?$/, '/' ),
	};

	// If any authentication credentials were provided, assign them now
	if ( options && ( options.username || options.password || options.nonce ) ) {
		this.auth( options );
	}

	return this
		// Configure custom HTTP transport methods, if provided
		.transport( options.transport )
		// Bootstrap with a specific routes object, if provided
		.bootstrap( options && options.routes );
}
function WPAPI( options ) {

	// Enforce `new`
	if ( this instanceof WPAPI === false ) {
		return new WPAPI( options );
	}

	if ( typeof options.endpoint !== 'string' ) {
		throw new Error( 'options hash must contain an API endpoint URL string' );
	}

	// Dictionary to be filled by handlers for default namespaces
	this._ns = {};

	this._options = {
		// Ensure trailing slash on endpoint URI
		endpoint: options.endpoint.replace(  /\/?$/, '/' ),
	};

	// If any authentication credentials were provided, assign them now
	if ( options && ( options.username || options.password || options.nonce ) ) {
		this.auth( options );
	}

	return this
		// Configure custom HTTP transport methods, if provided
		.transport( options.transport )
		// Bootstrap with a specific routes object, if provided
		.bootstrap( options && options.routes );
}
function WPAPI ( options ) { // Enforce `new` if ( this instanceof WPAPI === false ) { return new WPAPI ( options ) ; } if ( typeof options . endpoint !== 'string' ) { throw new Error ( 'options hash must contain an API endpoint URL string' ) ; } // Dictionary to be filled by handlers for default namespaces this . _ns = { } ; this . _options = { // Ensure trailing slash on endpoint URI endpoint : options . endpoint . replace ( / \/?$ / , '/' ) , } ; // If any authentication credentials were provided, assign them now if ( options && ( options . username || options . password || options . nonce ) ) { this . auth ( options ) ; } return this // Configure custom HTTP transport methods, if provided . transport ( options . transport ) // Bootstrap with a specific routes object, if provided . bootstrap ( options && options . routes ) ; }
Construct a REST API client instance object to create

@constructor WPAPI
@param {Object} options             An options hash to configure the instance
@param {String} options.endpoint    The URI for a WP-API endpoint
@param {String} [options.username]  A WP-API Basic Auth username
@param {String} [options.password]  A WP-API Basic Auth password
@param {String} [options.nonce]     A WP nonce for use with cookie authentication
@param {Object} [options.routes]    A dictionary of API routes with which to
bootstrap the WPAPI instance: the instance will
be initialized with default routes only
if this property is omitted
@param {String} [options.transport] An optional dictionary of HTTP transport
methods (.get, .post, .put, .delete, .head)
to use instead of the defaults, e.g. to use
a different HTTP library than superagent
Construct a REST API client instance object to create