1.0.7 • Published 2 years ago

@uon/http v1.0.7

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

UON HTTP

An http server module for use in a @uon/core application.

Installation

    npm i @uon/http

Usage

To start using @uon/http, include it in your app module's imports.

import { HttpModule } from '@uon/http';

@Module({
    imports: [
        HttpModule.WithConfig({
            plainPort: 8080
        })
    ]
})
export class MyAppModule {}

Routing requests

Http routing is done with @uon/router and the http module provides 2 routers: HTTP_ROUTER and HTTP_REDIRECT_ROUTER.

To declare routes you can do the following:

First declare a RouterOutlet with HttpRoute decorators on methods:

import { RouterOutlet, RouteParams } from '@uon/router';
import { HttpRoute, OutgoingResponse } from '@uon/http';

@RouterOutlet()
export class MyAppOutlet {

    // ctor with dependency injection 
    constructor(private response: OutgoingResponse) {}

    @HttpRoute({
        method: 'GET',
        path: '/say-hello/:param1'
    })
    myStaticPathRoute(params: RouteParams) {
        this.response.send(`Hello World! ${params.param1}`);
    }

}

Second, declare a list of routes that will be used by the HttpServer:

const routes: Routes = [
    {
        path:'/my-base-path',
        outlet: MyAppOutlet
    }
];

Finally, import RouterModule like so, to bind routes to the correct router:

@Module({
    imports: [
        RouterModule.For(HTTP_ROUTER, routes)
    ]
})
export class MyAppModule {}

Read more on routing here.

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.11.0

4 years ago

0.10.1

5 years ago

0.10.0

5 years ago

0.9.3

6 years ago

0.9.2

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago