1.0.3 • Published 4 years ago

crud-worker v1.0.3

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

crud-worker

Crud-worker aims to wrap the basic CRUD-Rest requests inside of a Web Worker for multithreaded API calls 🚀.

Currently supported 🥳:

  • POST
  • GET
  • PATCH
  • DELETE

Install:

npm i --save crud-webworker

Usage:

Import crud-webworker:

const crudworker = require('crud-worker')

or

import { crudworker } from 'crud-worker'

To POST data:

let body = {
      		title: 'foo',
      		body: 'bar',
      		userId: 1
    	 }

crudworker.post('https://jsonplaceholder.typicode.com/posts', JSON.stringify(body))
  	.then( (data) => {
        console.log({ data: JSON.parse(data)})
    })

To GET data, call the get function of crudworker:

crudworker.get('https://jsonplaceholder.typicode.com/users/1').then( (data) => {
	console.log({ data: JSON.parse(data)})
})

To PATCH Data:

let body = { title: 'foo'}

crudworker.patch('https://jsonplaceholder.typicode.com/posts/1', JSON.stringify(body))
    .then( (data) => {
        console.log({ data: JSON.parse(data)})
    })

And finally to DELETE data:

crudworker.delete('https://jsonplaceholder.typicode.com/users/1').then( (data) => {
    console.log({ data: JSON.parse(data)})
})