npm package: @kronos-integration/service-http
Description: http server
Latest version: 14.0.33

[![npm](https://img.shields.io/npm/v/@kronos-integration/service-http.svg)](https://www.npmjs.com/package/@kronos-integration/service-http)
[![License](https://img.shields.io/badge/License-0BSD-blue.svg)](https://spdx.org/licenses/0BSD.html)
[![bundlejs](https://deno.bundlejs.com/?q=@kronos-integration/service-http\&badge=detailed)](https://bundlejs.com/?q=@kronos-integration/service-http)
[![downloads](http://img.shields.io/npm/dm/@kronos-integration/service-http.svg?style=flat-square)](https://npmjs.org/package/@kronos-integration/service-http)
[![GitHub Issues](https://img.shields.io/github/issues/Kronos-Integration/service-http.svg?style=flat-square)](https://github.com/Kronos-Integration/service-http/issues)
[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2FKronos-Integration%2Fservice-http%2Fbadge\&style=flat)](https://actions-badge.atrox.dev/Kronos-Integration/service-http/goto)
[![Styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![Known Vulnerabilities](https://snyk.io/test/github/Kronos-Integration/service-http/badge.svg)](https://snyk.io/test/github/Kronos-Integration/service-http)

# @kronos-integration/service-http

http server

# API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### Table of Contents

*   [CTXBodyParamInterceptor](#ctxbodyparaminterceptor)
    *   [name](#name)
*   [CTXInterceptor](#ctxinterceptor)
    *   [name](#name-1)
*   [CTXJWTVerifyInterceptor](#ctxjwtverifyinterceptor)
    *   [name](#name-2)
*   [reportError](#reporterror)
    *   [Parameters](#parameters)
*   [CTX](#ctx)
    *   [Properties](#properties)
*   [HTTPEndpoint](#httpendpoint)
    *   [Parameters](#parameters-1)
*   [endpointRouter](#endpointrouter)
    *   [Parameters](#parameters-2)
*   [ServiceHTTP](#servicehttp)
    *   [Properties](#properties-1)
    *   [extendetName](#extendetname)
    *   [endpointFactoryFromConfig](#endpointfactoryfromconfig)
        *   [Parameters](#parameters-3)
    *   [isSecure](#issecure)
    *   [name](#name-3)
*   [WSEndpoint](#wsendpoint)
    *   [Parameters](#parameters-4)
    *   [Properties](#properties-2)
*   [authenticate](#authenticate)
    *   [Parameters](#parameters-5)

## CTXBodyParamInterceptor

**Extends CTXInterceptor**

Extracts params from request body.
Supported content types are:

*   application/json
*   application/x-www-form-urlencoded

### name

Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 'ctx-body-param'

## CTXInterceptor

**Extends Interceptor**

Basic interceptor providing/consuming http request/response.

### name

Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 'ctx'

## CTXJWTVerifyInterceptor

**Extends Interceptor**

Only forward requests if a valid JWT token is present.

### name

Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 'ctx-jwt-verify'

## reportError

Write WWW-Authenticate header.

### Parameters

*   `ctx` **any**&#x20;
*   `code` &#x20;
*   `error` **[Error](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error)?**&#x20;
*   `description` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?**&#x20;

## CTX

Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)

### Properties

*   `res` **ServerResponse**&#x20;
*   `req` **ServerRequest**&#x20;
*   `is` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)**&#x20;
*   `throw` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)**&#x20;

## HTTPEndpoint

**Extends SendEndpoint**

Endpoint to link against a http route.

The endpoint name may be in the form of '<METHOD>:<path>'.
Then <METHOD> will be used as http method
and <path> as the url path component.

### Parameters

*   `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** endpoint name
*   `owner` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** owner of the endpoint
*   `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**&#x20;

    *   `options.path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** url path component defaults to endpoint name
    *   `options.method` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** http method defaults to GET

## endpointRouter

### Parameters

*   `httpService` **HTTPServer**&#x20;

Returns **RequestListener**&#x20;

## ServiceHTTP

**Extends Service**

HTTP server.

### Properties

*   `server` **http.Server** only present if state is running

### extendetName

Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** name with url

### endpointFactoryFromConfig

On demand create RouteSendEndpoint´s.

#### Parameters

*   `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
*   `definition` **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) | [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))**&#x20;
*   `ic` &#x20;

Returns **Class** RouteSendEndpoint if path is present of name starts with '/'

### isSecure

Should we make a secure connection.

Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if key is present

### name

Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 'http'

## WSEndpoint

**Extends SendReceiveEndpoint**

Endpoint to link against a websocket route.

### Parameters

*   `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** endpoint name
*   `owner` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** owner of the endpoint
*   `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**&#x20;

    *   `options.path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** url path defaults to endpoint name

### Properties

*   `sockets` **[Set](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set)<[WebSocket](https://developer.mozilla.org/docs/WebSockets)>**&#x20;

## authenticate

Check sec-websocket-protocol header for presence of
'access\_token' and the token.
Throws if no valid token is present.

### Parameters

*   `service` **Service**&#x20;
*   `request` **any**&#x20;

# install

With [npm](http://npmjs.org) do:

```shell
npm install @kronos-integration/service-http
```

# license

BSD-2-Clause