npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@molecuel/http

v2.0.0-beta8

Published

HTTP module for molecuel Application framework

Downloads

21

Readme

@molecuel/http

NPM version Build Status Coverage percentage

HTTP module for the Molecuel framework

Based on the core modules and it's data functions http implments the automatic creation of HTTP endpoints with koa@2 async functions.

Endpoints can simply be defined in code with decorator functions and gets their url's through the project configuration. This guarantees a high flexibility and adds the option to reuse functions with different url's.

Functions need to be async and tagged as dataRead, dataCreate, dataDelete, dataUpdate or dataReplace. Parameters can be mapped by the mapDataParams function. All these decorators are provided by @molecuel/core to ensure that tagged functions can be reused with different services like FTP or websockets.

A running server is based on one or multiple classes using the decorators and a configuration mapping the urls to the classes.

The javascript part.

import {MlclCore, dataRead, dataCreate, dataUpdate, dataDelete, mapDataParams} from '@molecuel/core';
import {di, injectable} from "@molecuel/di";
import {MlclHttp, MlclHttpCoreRouter, MlclHttpMiddleware, MlclHttpRouter} from "@molecuel/http";

@injectable
class MyCreateTestRoutes {
  @mapDataParams([
      new MlclDataParam("id", "id", "integer", 25),
      new MlclDataParam("large", "size", "boolean"),
  ])
  @dataRead()
  public async dataReadeTest1(id, size) {
    return {
      id,
      size,
    };
  }
  @dataRead()
  public async dataReadeTest2() {
    return {};
  }
  @dataRead("application/rss+xml")
  public async dataReadeTestXml() {
    return "<xml></<xml>";
  }
  @dataCreate()
  public async dataCreateTest() {
    return true;
  }
  @mapDataParams([
    new MlclDataParam("id", "id", "integer", 25),
    new MlclDataParam("body", "postdata", "json"),
    new MlclDataParam("body.property", "child", "string"),
  ])
  @dataUpdate()
  public async dataUpdateTest(id, postdata, child) {
    return true;
  }
  @mapDataParams([
    new MlclDataParam("id", "id", "integer", 25),
  ])
  @dataReplace()
  public async dataReplaceTest(id) {
    return true;
  }
  @mapDataParams([
    new MlclDataParam("id", "id", "integer", 25),
  ])
  @dataDelete()
  public async dataDeleteTest(id) {
    return true;
  }
}
di.bootstrap(MlclCore, MlclHttpMiddleware, MlclHttp);

The configuration should be stored in ./config/development.json (or NODE_ENV) and look like this example:

{
  "http": {
    "security": {

    },
    "routes": [
      {
        "url": "/testread",
        "class": "MyCreateTestRoutes",
        "property": "dataReadeTest2"
      },
      {
        "url": "/testread/:id",
        "class": "MyCreateTestRoutes",
        "property": "dataReadeTest1"
      },
      {
        "url": "/testreadXml",
        "class": "MyCreateTestRoutes",
        "property": "dataReadeTestXml"
      },
      {
        "url": "/testcreate",
        "class": "MyCreateTestRoutes",
        "property": "dataCreateTest"
      },
      {
        "url": "/testupdate/:id",
        "class": "MyCreateTestRoutes",
        "property": "dataUpdateTest"
      },
      {
        "url": "/testreplace/:id",
        "class": "MyCreateTestRoutes",
        "property": "dataReplaceTest"
      },
       {
        "url": "/testdelete/:id",
        "class": "MyCreateTestRoutes",
        "property": "dataDeleteTest"
      }
    ]
  }
}