Package Exports
- @alkocats/http-ts
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@alkocats/http-ts) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
http-ts
Installation
npm install http-tsUsage
Example
All relevant imports for a minimal setup:
import { Request, Response } from 'express';
import { DataContainer, Controller, HTTPGet, HTTPServer } from '@alkocats/http-ts';The user interface for the data container:
interface User {
name: string;
password: string;
}The user container for the stored data the controller uses:
class UserContainer extends DataContainer<User[]> {
constructor() {
super([{
name: 'adam',
password: 'password1'
}]);
}
}The user controller which handles the user requests equipped with one GET-method:
class UserController extends Controller<UserContainer> {
@HTTPGet('/users')
public getUsers(request: Request, response: Response): void {
console.log('Request: %s %s ', request.method, request.url);
response.json(this.dataContainer.getData());
}
}Bringin all together:
const httpServer = new HTTPServer(80);
const userController = new UserController(new UserContainer());
httpServer.registerController(userController);
httpServer.start();API
Supported HTTP methods
@HTTPGet(path: string):
@HTTPPut(path: string):
@HTTPPost(path: string):
@HTTPDelete(path: string):
@HTTPHead(path: string):
@HTTPOptions(path: string):
@HTTPTrace(path: string):
@HTTPConnect(path: string):