RedPanda
RedPanda - A lightweight Javascript library for organizing your API calls, with fetch
and Promises
Features
- Fast and reliable, less code, complete more tasks
- Built on top of whatwg
fetch
API, Promises influenced - Strict type checking, less error prones
- Well tested with mocha
- Same code for browser (IE9+) and NodeJS, more will be added later...
Table of contents
Installation
npm i --save redpanda # or yarn add redpanda
RedPanda can also be adopted into your view file from awesome Jsdelivr
For older browser like IE11 which doesn't supports the Promise API natively, don't worry we've already packaged it for you. All you need to do is including only one line:
Simple requests
1. Calling API and handling response is so simple
net = net // Body {...}// Or static method calls likeRedPanda// ES5 code be likeRedPanda
2. Post a request and parse JSON responses
// POST return JSON --> JSON.parse object automaticallynet // {id: 3, text: 'Lorem ...'}
3. Get the responsed HTML
net // <p>Lorem Islum</p>
4. Calling a bundle of requests parallelly
net // Body {...}// Or static method calls likeRedPanda // Body {...}
5. Calling a bundle of requests sequentially
let sequence = netnet // Body {...}// Or static method calls likelet sequence = RedPandaRedPanda
Fetch API
This library is built on top of Github's Fetch polyfill for browser and Node native http fetch for NodeJS environment
1. Post a form
net
2. Post JSON
net
3. Post a file
var data = datanet
Build advanced AJAX application structure
1. Send a parallel stack
// Create some entry pointsnetnetnet // Create a parallel stacknet // Send the parallel stacknet // reponses par-3, par-1, par-2
Attach callback into last entry (entry-3)
net // point to last promise // responses par-3
Or wait for all reponses
net all // wait for all promise responses // responses [par-1, par-2, par-3]
2. Send a sequence (request sent only when previous one has responsed)
// Create a sequencenet // Send the sequence// And receive responses sequentiallynet // responses seq-1, seq-2, seq-3
Attach callback into last entry (entry-3)
net // point to last promise // responses seq-3
Or wait for all reponses
net all // wait for all promise responses // responses [seq-1, seq-2, seq-3]
3. Send a parallel stack that contains a sequence
// Create a parallel stack that contains a sequencenet // Send the parallel stack that contains a sequence// The requests inside sequence still keep their ordernet // responses par-3, par-1, seq-1, par-2, seq-2, seq-3
Attach callback into last entry (entry-3)
net // point to last promise, which is a PromiseCollection // responses seq-1, seq-2, seq-3
Or wait for all reponses
// The reponses of sequence still stack with each othernet all // wait for all promise responses // responses [par-1, par-2, par-3, [seq-1, seq-2, seq-3]]
Options reusing
RedPanda 's option inheritance will help you build a flexible option system
let net = // Common options// Send request including cookiesnet// Allow CORSnet// Common xsrf implementationnet
Want more?
Please dive deep into our API DOC
Message from author
Hello brothers and sisters. Your contribution is my treasure. Please send me a pull request if you have any new ideas. Or open an issues if you have problems using this project. I've got your back :D :D.
I am RedPanda, at your services.