0.1.2 • Published 8 years ago

crud-fetch v0.1.2

Weekly downloads
6
License
ISC
Repository
github
Last release
8 years ago

crud-fetch

A convenient wrapper for isomorphic-fetch.

Install

npm install crud-fetch

Motivation

Usage

It is inspired by Angular $http method for CRUD operation.

// Simple GET request example:
crudFetch.get('exampleUrl')
.then((body) => {
	// Successful callback with a response with status.ok is true. That is anything between 200 to 299.
}).catch(error) => {
	// Failure with either network issue, or status.ok is not true. 
}
// Simple POST request example:
crudFetch.post('exampleUrl', {
	title: 'Sample title',
	content: 'Sample content'
})
.then((body) => {
	// Successful callback.
}).catch(error) => {
	// Failure. 
}
// Simple PUT request example:
crudFetch.put('exampleUrl', {
	title: 'New title'
})
.then((body) => {
	// Successful callback.
}).catch(error) => {
	// Failure. 
}
// Simple DELTE request example:
crudFetch.remove('exampleUrl')
.then((body) => {
	// Successful callback.
}).catch(error) => {
	// Failure. 
}

There is a helpful guideline about when the native fetch api responds with status.ok. Fetch living standard

Currently supported operations:

  • GET
  • POST
  • DELETE
  • PUT