@minutemailer/middleman
v0.0.9
Published
Simple request handler for API requests.
Downloads
3
Readme
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);