1.1.0 • Published 6 years ago
@ezraobiwale/dpd v1.1.0
dpd
A Deployd frontend library
Installation
npm i @ezraobiwale/dpdor
yarn add @ezraobiwale/dpdUsage
This library allows you to decide which http and socket transports to use.
import dpd from '@ezraobiwale/dpd'
const server = dpd(httpTransport[, socketTransport])Important Note
The httpTransport must have a request method that takes a single object parameter:
request({
  method, // get | post | put | delete
  url, // the request url
  data // An object representing the data being sent
})Recommended Transports
Http
Socket
Http Usage
const collection = server.col('collection-name')The collection object has methods get, post, put, del and exec.
get
collection.get({ $sort: { name: 1 } }) // get a list
collection.get('abcd1234') // get an itempost
collection.post({ name: 'John Doe' }) // creates new itemput
collection.put({ name: 'Jane Doe' }) // updates an itemdel
collection.del('abcd1234') // deletes an item
**Note**
The response is always the returned value of the `request` method of the http transport.
### Socket Usage
Methods include `on`, `once`, `off` and `emit`:
#### on
```javascript
server.on('create', (/*...*/) => {
  // do something
})once
server.once('create', (/*...*/) => {
  // do something
})off
server.off('create', (/*...*/) => {
  // do something
})emit
server.emit('notify', { /*...*/ })Vue Usage
import Vue from 'vue'
import { VueInstaller } from '@ezraobiwale/dpd'
Vue.use(VueInstaller, httpTransport [, socketTransport])You can then access dpd as this.$dpd.