@anzerr/http.ts

Simple http server in ts

Usage no npm install needed!

<script type="module">
  import anzerrHttpTs from 'https://cdn.skypack.dev/@anzerr/http.ts';
</script>

README

Intro

GitHub Actions status | publish

Decorator for a simple http server

Install

npm install --save git+https://github.com/anzerr/http.ts.git
npm install --save @anzerr/http.ts

Example

import 'reflect-metadata';
import {Server, Controller, Get} from 'http.ts';
import {Injectable, Inject, Module} from 'inject.ts';

@Injectable()
class Log {
    count: number;

    constructor() {
        this.count = 0;
    }

    info(...arg) {
        this.count += 1;
        return console.log(this.count, ...arg);
    }

}

@Controller('user')
class Test extends Server.Controller {
    @Inject(Log)
    logger: Log;

    @Get()
    list() {
        this.logger.info('list');
        this.res.status(200).send('1');
    }

    @Get(':id')
    getUser() {
        this.logger.info('getUser');
        this.res.status(200).send('2');
    }

    @Get(':id/friends')
    getFriends() {
        this.logger.info('getFriends');
        this.res.status(200).send('3');
    }

}

new Server(3000)
    .withController([Test])
    .start();