leverage-plugin-http

1.0.4 • Public • Published

HTTP for Leverage!

This plugin supports the http component and middleware types.

Config

{
    path: 'a/b/c', // HTTP path as string
    method: 'get|post|delete|put|...' // Any express-supported HTTP method
}

API

method arguments description example
listen Number Have the HTTP server listen on a port http.listen(3000)

Example

import { Component } from 'leverage-js'

class MyComponent extends Component {
  constructor () {
    super()

    this.config = {
      type: 'http',
      http: {
        /*
         * Specify a `path` and `method`
         */
        path: '/',
        method: 'get'
      }
    }
  }

  /*
   * Then the callback for our type. This is supplied with
   *  the `request` and `response` objects from express.
   */
  http (request, response) {
    response.send('Hello World')
  }
}

Then just make sure to add the plugin to Leverage's manager along with your component instance!

import http from 'leverage-plugin-http'
import { manager } from 'leverage-js'

/* ... all the code from the previous example ... */

manager.plugin(http)

manager.add(new MyComponent) 

/*
 * Don't forget to listen on a port!
 */
http.listen(3000)

Readme

Keywords

Package Sidebar

Install

npm i leverage-plugin-http

Weekly Downloads

1

Version

1.0.4

License

ISC

Last publish

Collaborators

  • jakehamilton