@thermopylae/core.adapter.express
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@thermopylae/core.adapter.express

Version Node Version Documentation License: MIT

Express adapter for Thermopylae framework.

Install

npm install @thermopylae/core.adapter.express

Description

ℹ️ TL;DR;
Thermopylae framework allows you to use it's core.* modules with any of the existing web frameworks, such as express, fastify etc.
All you need to do is implementing HttpRequest and HttpResponse interfaces from @thermopylae/core.declarations.

This package contains implementations for HttpRequest and HttpResponse from @thermopylae/core.declarations.
These implementations are wrappers over Express request and response objects.

Usage

Bellow is a simple example of how this package can be used:

import { ExpressRequestAdapter, ExpressResponseAdapter, LOCATION_SYM } from '@thermopylae/core.adapter.express';
import { HttpStatusCode } from '@thermopylae/core.declarations';
import type { Request, Response } from 'express';

function handler(req: Request, res: Response) {
    const request = new ExpressRequestAdapter(req);
    const response = new ExpressResponseAdapter(res);

    // location needs to be computed by yourself and attached to Express request object, 
    // before passing it to Thermopylae functions
    request.raw[LOCATION_SYM] = {
        countryCode: 'MD',
        regionCode: 'K',
        city: 'Chisinau',
        latitude: null,
        longitude: null,
        timezone: null
    };
    
    console.log('New request received from ip ', request.ip, ' and device ', JSON.stringify(request.device));
    
    response.status(HttpStatusCode.Ok).send('Hello World!');
}

API Reference

API documentation is available here.

It can also be generated by issuing the following commands:

git clone git@github.com:marinrusu1997/thermopylae.git
cd thermopylae
yarn install
yarn workspace @thermopylae/core.adapter.express run doc

Author

👤 Rusu Marin

📝 License

Copyright © 2021 Rusu Marin.
This project is MIT licensed.

Package Sidebar

Install

npm i @thermopylae/core.adapter.express

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

12.1 kB

Total Files

8

Last publish

Collaborators

  • marinrusu1997