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 🙏

© 2024 – Pkg Stats / Ryan Hefner

redux-effects-fetch-fixture

v0.1.0

Published

Middleware for redux-effects-fetch to serve requests from a local fixture definition

Downloads

17

Readme

Build Status NPM Version

redux-effects-fetch-fixture

This is an extension for redux-effects-fetch, which lets you define fixtures for your FETCH actions. Now you are able to develop completely without any REST backend.

Installation

npm install redux-effects-fetch-fixture

Usage

This package is designed to be used in conjunction with redux-effects. Install it like this:

  import effects from 'redux-effects';
  import fetch from 'redux-effects-fetch';
  import fetchFixture from 'redux-effects-fetch-fixture';

  const fixtures = { /* your fixtures */ };
  const fetchMiddleware = isProduction ? fetch : fetchFixture(fixtures);
  applyMiddleware(effects, fetchMiddleware)(createStore);

Define fixtures

The fixture definition is structured like this:

'<path>': {
  '<HTTP-METHOD>': (body[, delegate[, params]]) => httpResponsePromise
}

The path-string supports URL parameters using the :param syntax.

response helpers

There are some response helpers to remove some boilerplate.

import {responses} from 'redux-effects-fetch-fixture';

// empty 200 response
responses.ok();

// 200 response with body
responses.ok({userId: 123});

// delayed 200 response
responses.okDelayed({})

The error helpers define a message and kind field in the response body. This will get more flexible in future releases.

import {responses} from 'redux-effects-fetch-fixture';

// rejected promise with Error(message)
responses.error('something went wrong');

// 500 response
responses.internalServerError;

// delayed 404 response
responses.notFound('user.notFound', 'The requested user was not found')

// delayed 401 response
responses.unauthorized('user.unauthorized', 'Authorize first to see this site')

// forbidden 403 response
responses.forbidden('user.unauthorized', 'You are not allowed to access this page')

Examples

A fixture could look like this

import {responses} from 'redux-effects-fetch-fixture';

const fixture = {
  '/foo': {
    // this delegates to another fixture
    'GET': (body, delegate) => delegate('/test', 'GET', body)
  },
  // simple definition
  '/test': {
    'GET': () => responses.ok({found: true})
  },
  // define responses for different http methods
  'user/:id': {
    'GET': (body, delegate, params) => responses.ok({ id: params.id }),
    'POST': () => responses.ok({created: true})
    'DELETE': () => responses.unauthorized('user.unauthorized', 'not allowed to delete this user')
  },
  // simulate exceptions
  'user/2': {
    'GET': () => responses.internalServerError
  }
};

Build

To build the library

npm run build

Release

npm version [patch|minor|major]
npm publish
git push
git push --tags