@uon/http
v1.0.7
Published
Framework for building precise REST applications
Downloads
4
Readme
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.