1.0.4 • Published 7 years ago

leverage-plugin-http v1.0.4

Weekly downloads
15
License
ISC
Repository
github
Last release
7 years ago

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

methodargumentsdescriptionexample
listenNumberHave the HTTP server listen on a porthttp.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)
1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago