http-services-core
A set of tools for the http service ...
Install
npm install --save http-services-core
SETTING
const httpServices = const HttpServices = // set domainHttpServicesdomain = 'http://localhost:4000' // set apiPathHttpServicesapiPath = '/api/v1' // set statusMessageHttpServicesstatusMessage = 'Request Success!'
GET / POST
// Promise/A+ HttpServices HttpServices // Async/Await async { try let ret = await HttpServices console catch error console } async { try let ret = await HttpServices console catch error console }
Other Method
const createAction createReducer statusToError getStatusError = // createAction const FETCH_SIGNIN_SUCCESS = 'FETCH_SIGNIN_SUCCESS'const FETCH_SIGNIN_FAILURE = 'FETCH_SIGNIN_FAILURE'const Response = data: id: 1 username: 'admin' status: code: 0 message: 'Request Success!' /*{ type: 'FETCH_SIGNIN_SUCCESS', payload: { data: { id: 1, username: 'admin' }, status: { code: 0, message: 'Request Success!' } }, error: null}*//*{ type: 'FETCH_SIGNIN_FAILURE', payload: null, error: Error}*/ // createReducer const ROOT_INITIAL_SUCCESS = 'ROOT_INITIAL_SUCCESS'const initialState = initial: falseconst action = const handlers = ROOT_INITIAL_SUCCESS: { return Object }/*{ initial: true}*/ // statusToError const Response = data: null status: code: 1024 message: 'Wraning Message!' /*{ loginError: { code: 1024, message: 'Wraning Message!' }}*//*{ loginError: 1024, loginMessage: 'Wraning Message!'}*/ // getStatusError const error = /*{ code: 1000, message: 'Abnormal error'}*/const error = 'Unexpected token < in JSON at position 0'/*{ code: 1000, message: 'Unexpected token < in JSON at position 0'}*/const error = errorresponse = status: 404 statusText: 'Not Found' /*{ code: 404, message: 'Not Found'}*/
License
this repo is released under the MIT License.