Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/l-chris/yar-node

Yar implemention for Nodejs.
https://github.com/l-chris/yar-node

node yar

Last synced: about 2 months ago
JSON representation

Yar implemention for Nodejs.

Awesome Lists containing this project

README

        

## yar-node

### ✨ Features:
- client[√]
- server[√]
- packager: json[√]、php[√]、msgpack[×]
- protocol: http[√]、tcp[×]、unix[×]

### Server
```javascript
const { YarServer } = require('yar-node');

class API {
someMethod(args) {}
}

const server = new YarServer(new API());

server.handle();
```

### Client
```javascript
const { YarClient } = require('yar-node');

const client = new YarClient('http://host/api/');

client.call('someMethod', { name: 'Chris' }).then(res => {
console.log(`reponse:${res}`);
});
```

### Yar Header
```C
typedef struct _yar_header {
unsigned int id; // transaction id
unsigned short version; // protocl version
unsigned int magic_num; // default is: 0x80DFEC60
unsigned int reserved;
unsigned char provider[32]; // reqeust from who
unsigned char token[32]; // request token, used for authentication
unsigned int body_len; // request body len
}
```

### Request
```javascript
{
i: '', // transaction id
m: '', // the method which being called
p: {} // parameters
}
```

### Response
```javascript
{
i: '', // transaction id
s: '', // status
r: '', // return value
o: '', // output
e: '' // error or exception
}
```