JSPM

  • Created
  • Published
  • Downloads 50
  • Score
    100M100P100Q54228F
  • License MIT

A Typescript HTTP server wrapper with express.

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

Build Status Test Coverage Maintainability npm version MIT License Known Vulnerabilities dependencies Status devDependencies Status

Installation

npm install http-ts

Usage

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):

Contributing

Credits

License