1.1.2 • Published 5 years ago

resf v1.1.2

Weekly downloads
1
License
ISC
Repository
-
Last release
5 years ago

ResF - Simplified Response message to client

A simple response message to client with a nice format

Build Status Coverage Status

Super simple to use

ResF is designed to be the simplest way to export data to client side based on Google format.

By providing data

const resf = require('resf');
const message = resf.dataResponse({ data: 'THIS IS SAMPLE TEST 1', httpCode: 200 });

By providing error

const resf = require('resf');
const message = resf.errorResponse({
    clientMessage: 'Please contact to supporter',
    httpCode: 404,
    technicalErrors: 'Cannot read value from url'
  });

Errors

You can display error response message.

 const message = resf.errorResponse({
    clientMessage: 'Please contact to supporter',
    httpCode: resf.code.Forbidden,
    technicalErrors: {
      error: 'Cannot load library',
      from: 'line 4 file test.js'
    }
  })

technicalErrors can have any variable type (string and object will be preferred)

 const message = resf.errorResponse({
    clientMessage: 'Please contact to supporter',
    httpCode: 404,
    technicalErrors: 'Cannot read value from url'
  });

Httpcode

The Http code can be found at resf.code

These code will be updated based on this site

 const code = resf.code.Forbidden // Should be 403

Message Builder (Updated soon)

The instruction of this method will be updated soon.

Example of data message builder

const responseMessage = resf.message()
    .addData('id', 1)
    .addData('name', 'Max')
    .addData('email', 'sample@gmail.com')
    .addData('phone', 1234567897)
    .removeFrom('email', 'data')
    .toOutput(resf.code.Created);

Example of error message builder

const responseMessage = resf.message()
    .addError('warning', 'Cannot run test file')
    .addError('from', 'line 4, test.ts')
    .addError('cmd', 'This is a sample command')
    .addError('idNumber', 5)
    .clientMessage(
      'There are something trouble on the server, please contact to our technical support.'
    )
    .toOutput(resf.code['Precondition Failed']);

Installation

Use the package manager npm to install resf.

npm i resf

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Bug

Please let me know if you have any trouble while using this package.

Current issues: It's need to reinstall everytime when to use a new version of this package.

License

ISC

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago