giuseppe-reqres-plugin
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

giuseppe request response plugin

This is a plugin for giuseppe which adds a @Req and a @Res parameter definition. Those definitions do inject the corresponding express object. @Req does inject the express request and @Res the express response object. So you have full control over what you do in your routes.

Note that the @Res parameter has the canHandleResponse flag set to true. Which means you need to actually handle the response in the route. Giuseppe won't run the result of your method through the return type handler.

A bunch of badges

Build Status Build Status npm Coverage status semantic-release Greenkeeper badge

Installation

To install this package, simply run

NPM

How to use

This is an example for a request injection:

import { Giuseppe, Controller, Get } from 'giuseppe';
import { GiuseppeReqResPlugin, Req } from 'giuseppe-reqres-plugin';
import { Request } from 'express';
 
@Controller()
class Ctrl{
    @Get()
    public func(@Req() request: Request): string {
        return request.get('Accept-Language'); // just return the string value of the header Accept-Language
    }
}
 
const app = new Giuseppe();
app.registerPlugin(new GiuseppeReqResPlugin());
app.start();

This is an example for a response injection:

import { Giuseppe, Controller, Get } from 'giuseppe';
import { GiuseppeReqResPlugin, Res } from 'giuseppe-reqres-plugin';
import { Response } from 'express';
 
@Controller()
class Ctrl{
    @Get()
    public func(@Res() response: Response): void {
        request
            .send('Foobar')
            .status('404')
            .end();
    }
}
 
const app = new Giuseppe();
app.registerPlugin(new GiuseppeReqResPlugin());
app.start();

Changelog

The changelog is generated by semantic release and is located under the release section.

Licence

This software is licenced under the MIT licence.

/giuseppe-reqres-plugin/

    Package Sidebar

    Install

    npm i giuseppe-reqres-plugin

    Weekly Downloads

    499

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    12.3 kB

    Total Files

    13

    Last publish

    Collaborators

    • cbuehler