npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vdata

v1.0.7

Published

JavaScript client of VDATA protocol. VDATA protocol is the best protocol for calling or responding a HTTP/HTTPS service.

Downloads

8

Readme

vdata

VDATA protocol is the best protocol for calling or responding a HTTP/HTTPS service.

Features

  • Defines the data protocol for HTTP/HTTPS based service Remote Process Call.
  • Defines common error codes and the range of user customized error codes.
  • Defines common status codes.
  • RESTfull api supported.
  • Cross-Origin Resource Sharing supported.
  • Send version request by HTTP_ACCEPT from client.
  • Respond in-service version of service from server.

Data Protocol/Format

{
	"name"			: "",		//	string,	name of service
	"url"			: "",		//	string,	address of service
	"version"		: "1.0",	//	string,	version of service
	"errorid"		: 0,		//	numeric,	error id
	"errordesc"		: "",		//	string,	desciption of error
	"parents"		: {},		//	array,	parent nodes
	"vdata"			: {}		//	user customized data. it might be a string, number, array or an object
}

Comnon error codes

| error defines | error code | remark | | ------------ | ------------- | ------------ | | ERROR_SUCCESS | 0 | successfully | | | | | | ERROR_UNKNOWN | -100000 | unknown errors | | ERROR_ACCESS_DENIED | -100001 | access denied | | ERROR_PARAMETER | -100002 | error in parameters | | ERROR_PERMISSION | -100003 | error in permission | | ERROR_EXPIRED | -100004 | error in expired | | ERROR_NOT_LOGGEDIN | -100005 | error in not logged in | | ERROR_FAILED_LOGGEDIN | -100006 | error in failed logged in | | | | | | ERROR_CREATE_INSTANCE | -100010 | error in creating instance | | ERROR_EXCEPTION | -100011 | error in exception | | | | | | ERROR_DB_SELECT | -100050 | error in selecting database | | ERROR_DB_UPDATE | -100051 | error in updating database | | ERROR_DB_INSERT | -100052 | error in inserting database | | ERROR_DB_DELETE | -100053 | error in deleting database | | ERROR_DB_DROP | -100054 | error in dropping database | | ERROR_DB_TRANSACTION | -100060 | error in transaction | | ERROR_DB_TABLE_NAME | -100065 | error in table name | | | | | | ERROR_REQUEST_VIA_IP | -100100 | bad request via ip request | | | | | | ERROR_MO_NOT_ENOUGH_COINS | -100200 | not enough coins | | ERROR_MO_HIRE_OVERDUE | -100201 | the hiring date is overdue | | ERROR_MO_TRANSACTION_TYPE | -100202 | error consume type | | | | | | ERROR_NETWORK | -100300 | error network | | ERROR_JSON | -100301 | error json | | ERROR_JSON_ERRORID | -100302 | error json.errorid | | ERROR_JSON_ERRORDESC | -100303 | error json.errordesc | | ERROR_JSON_VDATA | -100304 | error json.vdata |

the range of user customized error codes

| error defines | error code | remark | | ------------ | ------------- | ------------ | | | | | | ERROR_USER_START | 10000 | start of user customized error id | | ERROR_USER_END | 99999 | end of user customized error id

Cross-Origin Resource Sharing

use dekuan\vdata\CResponse;


$cResponse	= CResponse::GetInstance();

//
//	requests from *.domain1.com will be allowed
//
$cResponse->SetCorsDomains( [ '.domain1.com' ] );

//	...

Send Request to Server

1, Send GET request and receive VData response

use dekuan\vdata\CConst;
use dekuan\vdata\CRequest;


$cRequest	= CRequest::GetInstance();
$arrResponse	= [];
$nCall		= $cRequest->Get
(
	[
		'url'		=> 'http://api-account.yunkuan.org/api/login',
		'data'		=>
		[
			'u_name'	=> 'username',
			'u_pwd'		=> 'password',
			'u_keep'	=> 1
		],
		'version'	=> '1.0',
		'timeout'	=> 30,		//	timeout in seconds
		'cookie'	=> [],		//	array or string are both okay.
		'headers'	=> [],
	],
	$arrResponse
);
if ( CConst::ERROR_SUCCESS == $nCall &&
	$cRequest->IsValidVData( $arrResponse ) )
{
	//	arrResponse
	//		'errorid'	: error id
	//		'errordesc'	: error desc
	//		'vdata'		: virtual data
	//		'version'	: version of service
	//		'json'		: original json array
	print_r( $arrResponse );
}

2, Send POST request and receive VData response

use dekuan\vdata\CConst;
use dekuan\vdata\CRequest;


$cRequest	= CRequest::GetInstance();
$arrResponse	= [];
$nCall		= $cRequest->Post
(
	[
		'url'		=> 'http://api-account.yunkuan.org/api/login',
		'data'		=>
		[
			'u_name'	=> 'username',
			'u_pwd'		=> 'password',
			'u_keep'	=> 1
		],
		'version'	=> '1.0',
		'timeout'	=> 30,		//	timeout in seconds
		'cookie'	=> [],		//	array or string are both okay.
		'headers'	=> [],
	],
	$arrResponse
);
if ( CConst::ERROR_SUCCESS == $nCall &&
	$cRequest->IsValidVData( $arrResponse ) )
{
	//	arrResponse
	//		'errorid'	: error id
	//		'errordesc'	: error desc
	//		'vdata'		: virtual data
	//		'version'	: version of service
	//		'json'		: original json array
	print_r( $arrResponse );
}

3, Send GET/POST request and receive Raw response

use dekuan\vdata\CConst;
use dekuan\vdata\CRequest;


$cRequest	= CRequest::GetInstance();
$arrResponse	= [];
$nCall		= $cRequest->HttpRaw
(
	[
		'method'	=> 'POST',	//	'GET' / 'POST'
		'url'		=> 'http://api-account.yunkuan.org/api/login',
		'data'		=>
		[
			'u_name'	=> 'username',
			'u_pwd'		=> 'password',
			'u_keep'	=> 1
		],
		'version'	=> '1.0',
		'timeout'	=> 30,		//	timeout in seconds
		'cookie'	=> [],		//	array or string are both okay.
		'headers'	=> [],
	],
	$arrResponse
);
if ( CConst::ERROR_SUCCESS == $nCall &&
	$cRequest->IsValidRawResponse( $arrResponse ) )
{
	//	arrResponse	- Array
	//		'data'		: http data
	//		'status'	: status code
	//		'headers'	: response headers
	print_r( $arrResponse );
}

Respond to Client

1, Respond by json encoded string

use dekuan\vdata\CResponse;


$cResponse	= CResponse::GetInstance();

$cResponse->SetServiceName( 'Test of responding array VData' );
$cResponse->SetServiceUrl( 'http://www.ladep.cn/' );
$arrVData	= $cResponse->GetVDataString
(
	0,
	"error desc",
	[ "info" => "User customized info" ],
	$cResponse->GetDefaultVersion()
);

echo( $arrVData );

2, Respond by json array

use dekuan\vdata\CResponse;


$cResponse	= CResponse::GetInstance();

$cResponse->SetServiceName( 'Test of responding array VData' );
$cResponse->SetServiceUrl( 'http://www.ladep.cn/' );
$arrVData	= $cResponse->GetVDataArray
(
	0,
	"error desc",
	[ "info" => "User customized info" ],
	$cResponse->GetDefaultVersion()
);

print_r( $arrVData );

3, Respond by Laravel response instance

use dekuan\vdata\CResponse;


$cResponse	= CResponse::GetInstance();

$cResponse->SetServiceName( 'Test of responding array VData' );
$cResponse->SetServiceUrl( 'http://www.ladep.cn/' );
$nCall	= $cResponse->Send
(
	0,
	"error desc",
	[ "info" => "User customized info" ],
	$cResponse->GetDefaultVersion()
);

Testing


mocha tests/js/index.test.js