Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/morjodrom/fetcheer
https://github.com/morjodrom/fetcheer
Last synced: 25 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/morjodrom/fetcheer
- Owner: Morjodrom
- License: mit
- Created: 2018-03-07T18:56:51.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-07-15T20:25:45.000Z (over 6 years ago)
- Last Synced: 2024-12-14T10:06:32.341Z (25 days ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fetcheer
A small JS fetch wrapper to work in a couple with [JSend][1].
Feel free to use as a boilerplate and a plain extension point.###
##! The library is unstable and not intended to a direct usage, please, consider using it as a boilerplate.[1]: http://labs.omniti.com/labs/jsend
# Basic usage
```javascript
import Fetcheer from 'fetcheer'
return Fetcheer.request(input, init) // purely like fetch(input, init)
.then(Fetcheer.check200) // trivial 200 code checker
.then(response => {
// standard object of the Response interface
})
.catch(error => {
// server responded with the code different from 200
})
```# Usage with JSend
```javascript
import Fetcheer from 'fetcheer'
Fetcheer.getJsend('/some-handler/')
.then(jsendResponse => {
// do something with jsend
})
.catch(error => {
// server responded with the code different from 200
// or jsend is not parsed
})
```# Post queries
```javascript
import Fetcheer from 'fetcheer'
/**
* @type {{name: string, address: {street: string}, photo: File}}
*/
const user = {
name: 'Ivan',
address: {street: 'Ever Green str.'},
photo: file
}
const postBody = Fetcheer.objectToFormData(user)
const postOptions = Fetcheer.getPostOptions(postBody)
return Fetcheer.getJsend('/user-save-handler/', postOptions)
.then()
// ...
.catch()
```# JSend handling sugar
```javascript
import Fetcheer from 'fetcheer'
Fetcheer.getJsend('some url')
.then(Fetcheer.checkJsendSuccess) // check if the jsend has success status
.then(data => {
// this code is called ONLY for successful a JSend
})
.catch(/** @param {string|string[]|*} error - message from jsend with error status or data from jsend fail */
error => {
})```