All Projects → janryWang → Mfetch

janryWang / Mfetch

Licence: mit
mfetch will provide you with a strong ability to request resource management

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Mfetch

miniprogram-network
Redefine the Network API of Wechat MiniProgram (小程序网络库)
Stars: ✭ 93 (+3.33%)
Mutual labels:  fetch, promise, request
Create Request
Apply interceptors to `fetch` and create a custom request function.
Stars: ✭ 34 (-62.22%)
Mutual labels:  promise, fetch, request
hermes-js
Universal action dispatcher for JavaScript apps
Stars: ✭ 15 (-83.33%)
Mutual labels:  fetch, promise, request
Wretch
A tiny wrapper built around fetch with an intuitive syntax. 🍬
Stars: ✭ 2,285 (+2438.89%)
Mutual labels:  promise, fetch, request
Ngx Restangular
Restangular for Angular 2 and higher versions
Stars: ✭ 787 (+774.44%)
Mutual labels:  restful, fetch, request
electron-request
Zero-dependency, Lightweight HTTP request client for Electron or Node.js
Stars: ✭ 45 (-50%)
Mutual labels:  fetch, request
Trae
📮 Minimalistic Fetch based HTTP client
Stars: ✭ 257 (+185.56%)
Mutual labels:  fetch, request
React Request
Declarative HTTP requests for React
Stars: ✭ 340 (+277.78%)
Mutual labels:  fetch, request
Node Fetch
A light-weight module that brings the Fetch API to Node.js
Stars: ✭ 7,176 (+7873.33%)
Mutual labels:  promise, fetch
legible
the cleanest way to make http requests in js / node
Stars: ✭ 49 (-45.56%)
Mutual labels:  fetch, request
Ky Universal
Use Ky in both Node.js and browsers
Stars: ✭ 421 (+367.78%)
Mutual labels:  fetch, request
Ky
🌳 Tiny & elegant JavaScript HTTP client based on the browser Fetch API
Stars: ✭ 7,047 (+7730%)
Mutual labels:  fetch, request
wumpfetch
🚀🔗 A modern, lightweight, fast and easy to use Node.js HTTP client
Stars: ✭ 20 (-77.78%)
Mutual labels:  fetch, request
vue-methods-promise
Let Vue methods support return Promise
Stars: ✭ 35 (-61.11%)
Mutual labels:  fetch, request
Gretchen
Making fetch happen in TypeScript.
Stars: ✭ 301 (+234.44%)
Mutual labels:  fetch, request
cmn-utils
公共函数&请求封装
Stars: ✭ 43 (-52.22%)
Mutual labels:  fetch, request
Fetch
A window.fetch JavaScript polyfill.
Stars: ✭ 25,118 (+27808.89%)
Mutual labels:  promise, fetch
Composable Fetch
A library that brings composition to http requests & solves most common tasks
Stars: ✭ 23 (-74.44%)
Mutual labels:  fetch, request
Wretch Middlewares
Collection of middlewares for the Wretch library. 🎁
Stars: ✭ 42 (-53.33%)
Mutual labels:  fetch, request
parcel-plugin-goodie-bag
provides the Promise and fetch goodies needed for IE(11) support w/ parcel bundle loading
Stars: ✭ 15 (-83.33%)
Mutual labels:  fetch, promise

mfetch

mfetch will provide you with a strong ability to request resource management, at the same time, you can use it very simply

Installation

You can install with npm.

npm install mfetch

Usage

The mfetch not only supports any request method, but also supports jsonp request, and it also supports request/response global interceptor.

Fetch something in sample way


import {fetch} from 'mfetch'

fetch('http://xxxx',{
	params:{
		arg:'This is arg'
	}
}) .then(res=>res.json())
.then(res=>console.log(res))

or

fetch({
    url:'http://xxxx',
    params:{
        arg:'This is arg'
    }
}).then(res=>res.json())
.then(res=>console.log(res))


Fetch something with complex parameters


import {fetch} from 'mfetch'

const complex_params = {
    param1:'param1',
    param2:'param2'
}

fetch({
    url:'http://xxxx',
    params:{
        arg:'This is arg',
        obj:JSON.stringify(complex_params)
    }
}).then(res=>res.json())
.then(res=>console.log(res))


Fetch jsonp

import {fetch} from 'mfetch'

fetch({
    url:'http://xxxx',
    method:'jsonp',
    params:{
        arg:'This is arg'
    }
}).then(res=>res.json())
.then(res=>console.log(res))


send request with cookie

CORS request

import {fetch} from 'mfetch'

fetch({
    url:'http://xxxx',
    method:'jsonp',
    params:{
        arg:'This is arg'
    },
    credentials:'include'
}).then(res=>res.json())
.then(res=>console.log(res))

same domain

import {fetch} from 'mfetch'

fetch({
    url:'http://xxxx',
    method:'jsonp',
    params:{
        arg:'This is arg'
    },
    credentials:'same-origin'
}).then(res=>res.json())
.then(res=>console.log(res))

Fetch FormData


import {fetch} from 'mfetch'


fetch({
    url:'http://xxxx',
    method:'post',
    headers:{
        'Content-Type':'multipart/formdata;charset=utf8'
    },
    params:{
        arg:'This is arg'
    }
}).then(res=>res.json())
.then(res=>console.log(res))


Use interceptor to intercept requests

import {fetch,interceptor} from 'mfetch'


interceptor({
    request(options){
        options.url += '&aaa=bbb'
        return options         // You can solve the asynchronous problem by returning the Promise object.
    },
    response(response){
        return response.json()
    }
})



fetch({
    url:'http://xxxx',
    params:{
        arg:'This is arg'
    }
}).then(res=>console.log(res))


Use the resource API to abstract your requests

import {resource} from 'mfetch'

const getSiteInfo = resource('http://xxxxx',{/** options **/})
const getUserInfo = resource({
    url:'http://xxxx',
    method:'jsonp'
})

const getCombineInfo = resource((data)=>{
    return getSiteInfo(data)
        .then(res=>res.json())
        .then(res=>getUserInfo(res.data))
})

getCombineInfo({
    params:'params'
}).then(res=>res.json())
.then((res)=>{
    console.log(res)
})


Use URI Template(RFC6570)


import {resource} from 'mfetch'

const getSiteInfo = resource('/{id}?xxx',{uriTemplate:true})

getSiteInfo({
    id:12333
})
.then(res=>res.json())
.then(()=>{


})


API

fetch

fetch(url : String,[options : Object]) : Promise

fetch(options : Object) : Promise

resource

resource(url : String,[options : Object]) : Promise

resource(options : Object) :Promise

resource(callback : Function) :Promise

interceptor

interceptor(Interceptors : Object)

extension

extension([plugins,...])

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].