1.2.0 • Published 5 years ago

@devswoop/hermes v1.2.0

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

Hermes

Simple, centralized and promised API routes manager for the browser.

import Hermes from 'Hermes'

Hermes.init({
  baseUrl: 'serverHostname',
  port: 3000
}, [
  {
    name: 'userLogin',
    method: 'post',
    path: 'login'
  }
])

// POST http://localhost:3000/login
Hermes.run('userLogin', {
  data: {
    mail: 'mail@example.com',
    password: 'secretPassword'
  }
}
.then(data => {
  // ...
})
.catch(error => {
  // ...
})

You can also add middlewares like that, these will requests without errors

Hermes.listener(data => new Promise((resolve, reject) => {
  // You can edit the data
  data.date = Date.now()
  resolve(data)
}))

You can do the same with errors

Hermes.catch(data => new Promise((resolve, reject) => {
  if (data.message === 'You are not authenticated') {
    window.location.reload()
  } else {
    reject(data)
  }
}))
1.2.0

5 years ago

1.1.0

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