1.1.0 • Published 8 years ago

slim-fetchy v1.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

slim-fetchy 🚀

Enhanced fetch API.

https://github.com/justsml/slim-fetchy.git

  • ✔ Simple HTTP request
  • ✔ Small
  • ✔ Encode POST Body
  • ✔ Response parser
  • ✔ Smarter error handling

Why?

I was listening to Slim Shady EP. And all the other names were taken.

Install

# Add to your project:
npm install slim-fetchy --save

# Optionally, clone Code:
git clone https://github.com/justsml/slim-fetchy.git
cd slim-fetchy
npm install
npm test

Seriously, Why?

The current fetch API spec and the implementation from Github are ill-suited for the majority of use-cases.

Specifically, JSON-backed services require repetitive encoding and response parsing. Additionally, acquiring HTTP response body content requires 2 promise .then() calls. (Some Promise libraries, like bluebird will automatically handle this for you.)

I decided to create a wrapper to eliminate frequent hurdles & repetitive code.

slim-fetchy JSON optimized usage:

// Using slim-fetchy (optional: es6 destructuring)
fetch('/users.json')
  .then(({body}) => {
    document.body.innerHTML = body; // SINGLE `.then` - has access to headers, status & statusText
  })

Compared to current fetch API/spec:

// Using github's implementation
fetch('/users.json')
  .then(function(response) {
    return response.text()
  }).then(function(body) {
    document.body.innerHTML = body
  })

Stats & Support Info

  • Requires Promise support - native or polyfilled. Tested with Bluebird and es6-promise
  • Runs on: Browser & NodeJS
  • Gzipped: 2.8K
1.1.0

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago