@ezraobiwale/dpd

A Deployd frontend library

Usage no npm install needed!

<script type="module">
  import ezraobiwaleDpd from 'https://cdn.skypack.dev/@ezraobiwale/dpd';
</script>

README

dpd

A Deployd frontend library

Installation

npm i @ezraobiwale/dpd

or

yarn add @ezraobiwale/dpd

Usage

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 item

post

collection.post({ name: 'John Doe' }) // creates new item

put

collection.put({ name: 'Jane Doe' }) // updates an item

del

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.