Socket
Book a DemoInstallSign in
Socket

@minutemailer/middleman

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@minutemailer/middleman

Simple request handler for API requests.

latest
Source
npmnpm
Version
0.0.9
Version published
Maintainers
1
Created
Source

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);

FAQs

Package last updated on 20 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts