1.2.3 • Published 5 years ago

@poppinss/http-server v1.2.3

Weekly downloads
32
License
MIT
Repository
github
Last release
5 years ago

Http Server

circleci-image npm-image license-image

Node.js HTTP server with a slick router used by AdonisJs. Think of it as an ExpressJs style server written in Typescript.

Table of contents

Usage

Install the package from npm registry as follows:

npm i @poppinss/http-server

# yarn
yarn add @poppinss/http-server

and then use it as follows:

import { createServer } from 'http'

import { Logger } from '@poppinss/logger'

import {
  Server,
  Router,
  MiddlewareStore,
  routePreProcessor,
  HttpContext,
} from '@poppinss/http-server'

// more on middleware later
const middleware = new MiddlewareStore()
const router = new Router((route) => {
  routePreProcessor(route, middleware)
})
router.get('/', async () => 'hello world')

const server = new Server(HttpContext, router, middlewareStore, new Logger(), config)
router.commit()
server.optimize()

createServer(server.handle.bind(server)).listen(3000)

Wow! too much boilerplate. That's why we recommend using AdonisJs over wiring up things by hand.

MiddlewareStore

The middleware store is used to store global and named middleware. The global middleware runs on all HTTP requests and named one can be attached to a given route.

const middleware = new MiddlewareStore()

// Global middleware
middleware.register([
  async function () {},
  async function () {},
])

// Named middleware
middleware.registerNamed({
  auth: async function () {}
})

The named middleware can be referenced on the route as follows:

router.get('/', async function () {
}).middleware(['auth'])

Router

AdonisJs has one of the most advanced and fast router. It has support for Route groups, Resourceful resources and many more.

router.group(() => {
  router.get('/', async () => {
  })
}).prefix('v1')

Profiler action labels

Following is the list of actions profiled during an HTTP request

  • http:request
  • http:before:hooks
  • http:route:match
  • http:route:stack
  • http:after:hooks
  • http:route:closure
  • http:route:controller

We recommend you to check the API docs to get a complete reference of all the classes.

API

Following are the autogenerated files via Typedoc

Maintainers

Harminder virk

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago