0.1.38 • Published 5 years ago

icore v0.1.38

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

Iсore

License Build Status Coverage Status Known Vulnerabilities

Icore is a framework a high-level to build strict web application. Allows the developer to focus on the final handler.

Features

This module for Node.js® implemented by following the ECMAScript® 2018 Language Specification Standard

  • strict interface
  • not immutable context
  • routing implements a binary tree
  • all asynchronous functions on promises
  • error handling

Install

To use iсore in your project, run:

npm i icore

Table of Contents

class Application

class Route

class Inquiry

class Application

constructor: new Application(options)

For example:

const icore = require('icore');

const app = new icore.Application({
  port: 3000
});

app.listenHttp(router)

Starts the HTTP server listening for connections. These arguments are documented on nodejs.org.

index.js

const icore = require('icore');
const router = require('./router');

const app = new icore.Application({
  port: 3000
});

app.listenHttp(router);

Start script in terminal:

$ node index.js
Server started on http://localhost:3000

app.close()

Stops the server from accepting new connections.

app.server

In this variable, an instance of the server will be assigned after a successful listen installation.

app.context

This empty [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object). You may add additional properties to inq.context by editing app.context.

app.context.db = db();

class Route

The router is made up of instances class Route.

router

Routing will be done:

MethodURL
GEThttp://example.com
GEThttp://example.com/catalog
GEThttp://example.com/logs_0
GEThttp://example.com/logs_1
POSThttp://example.com/catalog/books

Extends the Node.js events module.

Event: 'error'

The 'error' event is emitted if throw an exception. The listener callback is passed a single Error argument when called. The server is not closed when the 'error' event is emitted.

constructor: new Route(options)

When defining a route in icore you need one basic element - the handler.

Simple example use Route class:

const homepage = new Route({
  async handler(inq) {
    return {
      status: 200,
      header: {
        'Content-Type': 'text/html; charset=utf-8'
      },
      body: 'Hello World!'
    };
  }
});

route.route(options)

Uses the same interface as the class constructor.

const catalog = homepage.route({
  method: 'catalog',
  async handler(inq) {
    return {};
  }
});

route.find(paths, index)

This method is intended for class Application use.

route.method

route.handler

route.finish

route.childs

class Inquiry

A class Application context encapsulates node's request and response objects into a single object which provides many helpful methods for writing web applications and APIs.

constructor: new Inquiry(req, cookie)

The constructor will be auto called whenever a new request is established.

inq.read(options)

To start reading the body of the incoming message.

async handler(inq) {
  const data = await inq.read();
}

inq.pipe(stream, options)

To start reading the body of an incoming message as a stream

async handler(inq) {
  inq.pipe(writeStream);
}

inq.queries

inq.method

inq.headers

inq.context

0.1.38

5 years ago

0.0.37

7 years ago

0.0.36

7 years ago

0.0.35

7 years ago

0.0.34

7 years ago

0.0.33

7 years ago

0.0.32

7 years ago

0.0.31

7 years ago

0.0.30

7 years ago

0.0.29

7 years ago

0.0.28

7 years ago

0.0.27

7 years ago

0.0.26

7 years ago

0.0.25

7 years ago

0.0.24

7 years ago

0.0.23

7 years ago

0.0.22

7 years ago

0.0.21

7 years ago

0.0.20

7 years ago

0.0.19

7 years ago

0.0.18

7 years ago

0.0.17

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago