@kronos-integration/service-http
Version:
206 lines (130 loc) • 7.03 kB
Markdown
[](https://spdx.org/licenses/0BSD.html)
[](https://typescriptlang.org)
[](https://github.com/Kronos-Integration/service-http/issues)
[](https://actions-badge.atrox.dev/Kronos-Integration/service-http/goto)
[](https://github.com/prettier/prettier)
[](http://commitizen.github.io/cz-cli/)
[](https://snyk.io/test/github/Kronos-Integration/service-http)
[](https://coveralls.io/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** 
* `code`  
* `error` **any?** 
* `description` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** 
## CTX
Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
### Properties
* `res` **ServerResponse** 
* `req` **ServerRequest** 
* `is` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** 
* `throw` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** 
## 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)** 
* `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** 
Returns **RequestListener** 
## 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)** 
* `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))** 
* `ic`  
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)** 
* `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)>** 
## authenticate
Check sec-websocket-protocol header for presence of
'access\_token' and the token.
Throws if no valid token is present.
### Parameters
* `service` **Service** 
* `request` **any** 
# install
With [npm](http://npmjs.org) do:
```shell
npm install @kronos-integration/service-http
```
# license
BSD-2-Clause