csf-symmetra

1.0.0 • Public • Published

The Http Client for GalaxyCrowd Fund

Feature

  1. Promise base http client
  2. Set Json as default format
  3. Log request and response information

How to use

import symm from 'csf-symmetra';

try {
  const responseJson = await symm.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  });
  console.log(responseJson);
} catch (error) {
  console.log(error);
}

OR

import symm from 'csf-symmetra';

symm.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  })
  .then(function (responseJson) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

Set up custom http client

const customSymm = symm.create({
  headers: {
    'Authorize': 'xxxxx',
  },
  baseURL: 'http://baseurl.com',
});

Get full response

try {
  const response = await symm.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  }, {
    full: true,
  });
  console.log(response);
} catch (error) {
  console.log(error);
}

Hide request and response params in log

try {
  const response = await symm.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  }, {
    logParams: false,
  });
  console.log(response);
} catch (error) {
  console.log(error);
}

error object

{
  message,
  status,
  data
}

Readme

Keywords

none

Package Sidebar

Install

npm i csf-symmetra

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

13.4 kB

Total Files

15

Last publish

Collaborators

  • shuhui