Code Monkey home page Code Monkey logo

ferry-mw-core's Introduction

@ferry-middleware/ferry-mw-core

By YanPan

简介

[ferry] HTTP 中间件核心服务,用于简化通过 ferry 发出的 HTTP 请求的hooks钩子 它适用于全局 ferry 和实例对象。

为什么不使用拦截器?

使用 ferry 拦截器会使代码与 ferry 实例紧密耦合并且更难进行功能测试。

作为中间件服务模块核心:

  • 与 ferry 的松耦合
  • 非常容易测试中间件类

它提高了集中式挂钩策略的可读性和可重用性。

使用示例

import ferry, { ferryPst } from '@ferry-core/ferry';
import { Service } from '@ferry-middleware/ferry-mw-core';

const service = new Service(ferry);

service.register({
  onRequest(config) {
    console.log('onRequest');
    return config;
  },
  onSync(promise) {
    console.log('onSync');
    return promise;
  },
  onResponse(response) {
    console.log('onResponse');
    return response;
  }
});

console.log('Ready to fetch.');

// Just use ferryPst like you would normally.
ferryPst('https://jsonplaceholder.typicode.com/posts/1')
  .then(({ data }) => console.log('Received:', data));

ferry-mw-core's People

Contributors

yanpanmichael avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.