0.0.9 • Published 6 years ago

@minutemailer/middleman v0.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

Middleman

Simple request handler for API requests. The goal is to use Middleman to configure global validation and response handlers.

The Middleman has built in handler for these responses:

  • Unauthenticated (401)
  • Session expired (418)
  • General error (everything that is above 300)

The appropriate exception will be thrown when any of these statuses is present in the response.

Usage

The recommended way is to create a class that extends to Middleman class so you can fully configure it to suit the needs of your app.

The handleSuccess method is a good place to start. A place where you can add redirects and other defined response rules you might have.

import Middleman from 'middleman';
import Notifications from 'notifications';

class API extends Middleman {
    /**
     * Handle success responses
     * @param {Object}  data Minutemailer data
     */
    handleSuccess = (data) => {
        if ('notifications' in data) {
            Notifications.add(data.notification);
        }

        return data;
    };
}

const photos = new API('/api/photos');

photos.get().then(console.log);
0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago