npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@ykkjs/mock-http-request

v1.0.5

Published

Mock http request for env.development ~

Readme

mock-http-request

Mock http-request for env.development

供开发环境使用的 mockRequest 方法

Install

Using npm to install:

npm i '@ykkjs/mock-http-request' -D

Using yarn or pnpm:

# with yarn
yarn add '@ykkjs/mock-http-request' -D

# with pnpm
pnpm add '@ykkjs/mock-http-request' -D

Usage Example

// 导入 mockRequest
import { mockRequest, STATUS_TYPE } from '@ykkjs/mock-http-request';
// 导入 mock-json-data
import MOCK_LIST_DATA from './mockData/getList.json';
import MOCK_DETAIL_DATA from './mockData/getDetail.json';

// Example - 获取列表数据
const getList = function (data: GetListParam) {
  // 1、注释生产代码
  // return httpRequestAdapter<GetListRes>({
  // 2、使用开发环境下的 mockRequest
  return mockRequest<GetListRes>({
    url: baseURL + '/list',
    method: 'post',
    data,
    mockConfig: {
      responseData: MOCK_LIST_DATA,
      delaytime: 3000,
      status: STATUS_TYPE.EMPTY,
      emptyKey: 'data.list',
    }
  });
};

// Example - 获取详情数据
const getkDetail = function (data: DetailParam) {
  // 1、注释生产代码
  // return httpRequestAdapter<GetDetailRes>({
  // 2、使用开发环境下的 mockRequest
  return mockRequest<GetDetailRes>({
    url: baseURL + '/detail',
    method: 'get',
    mockConfig: {
      responseData: MOCK_DETAIL_DATA,
    }
  });
};

Usage 说明

快速使用

1、导入 mock 方法:mockRequest

2、导入 mock 数据:本地的 json 文件。

3、使用 mock 方法:mockRequest 入参中的 mockConfig.responseData 设置为导入的 mock-json-data

进阶使用

1、导入请求状态的枚举值:STATUS_TYPE;

2、关于 mockRequest 入参的 mock 配置项 mockConfig:

  • mockConfig.responseData :必传的 mock-json-data

  • mockConfig.delaytime :请求延迟(默认 200 毫秒)。

  • mockConfig.status :请求状态(默认 STATUS_TYPE.SUCCESS),根据需求还可以模拟请求状态为 STATUS_TYPE.LOADINGSTATUS_TYPE.FAILEDSTATUS_TYPE.EMPTY

  • mockConfig.emptyKey :需要设置为空数据的字段(默认 'data'),当请求状态配置的是空状态时,即 mockConfig.status = STATUS_TYPE.EMPTY,此时还可以配置本地 mock 数据中需要设置为空的字段,例如 emptyKey: 'data.list'

❗️需要注意的是,通过配置项来模拟空状态的实现原理是将某个字段设置为null。如果需要设置为其他空数据(例如 {}[]''等)需要通过修改本地 mock-json-data 来实现。