0.6.0 • Published 2 years ago

@machinat/http v0.6.0

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

Http Module

This module provide HTTP listening capability to all the services require it. For example, to serve a webhook for subscribing events from chat platform.

Install

npm install @machinat/core @machinat/http
# or with yarn
yarn add @machinat/core @machinat/http

Docs

Check the package reference.

Setup

Use listenOptions to set the network options for server.listen().

import Machinat from '@machinat/core';
import Http from '@machinat/http';

const app = Machinat.createApp({
  modules: [
    Http.initModule({
      listenOptions: {
        port: 8080,
        host: 'localhost',
      }
    }),
  ],
});

Usage

Provide Http.RequestRouteList or Http.UpgradeRouteList (for WebSocket) to register RPC style routes. All the requests under the registered path will be received by the handler. You can also use default: true to catch all unmatch requests.

const app = Machinat.createApp({
  modules: [
    Http.initModule({ /* ... */ }),
  ],
  service: [
    { // route listening to /api
      provide: Http.RequestRouteList,
      withValue: {
        name: 'my_api',
        path: '/api',
        handler: (req, res) => {
          // handle http requests
        },
      }
    },
    { // default request route
      provide: Http.RequestRouteList,
      withValue: {
        name: 'default',
        default: true,
        handler: (req, res) => {
          // catch requests not matching any route
        },
      }
    },
    {  // handle WebSocket connection
      provide: Http.UpgradeRouteList,
      withValue: {
        name: 'web_socket',
        path: '/',
        handler: (req, head, socket) => {
          // handle http upgrade requests
        },
      }
    },
  ],
});
0.6.0

2 years ago

0.6.0-canary.0

2 years ago

0.6.0-beta.0

2 years ago

0.6.0-canary.3

2 years ago

0.5.0-beta.40

2 years ago

0.5.0-beta.38

2 years ago

0.5.0-beta.36

2 years ago

0.5.0-beta.14

2 years ago

0.5.0-beta.39

2 years ago

0.5.0

2 years ago

0.5.0-beta.1

3 years ago

0.5.0-beta.0

3 years ago

0.4.1-alpha.44

3 years ago

0.4.1-alpha.34

3 years ago

0.4.1-alpha.33

3 years ago

0.4.1-alpha.29

3 years ago

0.4.1-alpha.28

3 years ago

0.4.1-alpha.27

3 years ago

0.4.1-alpha.3

3 years ago

0.4.1-alpha.1

3 years ago

0.4.0-beta.1

3 years ago

0.4.0-beta.0

3 years ago

0.3.0-beta.2

4 years ago

0.3.0-beta.1

4 years ago

0.3.0-beta.0

4 years ago

0.2.0-beta.0

4 years ago