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

pumlhorse-express

v0.2.0

Published

Router for Express that uses Pumlhorse as a controller

Downloads

1

Readme

pumlhorse-express

This project allows you to use Pumlhorse as a controller engine in Express.

Setup

First, see the Express documentation for setting up a project. Then run npm install --save pumlhorse-express.

Next, in your server file, add the following code:

//This is probably already in your file
const express = require('express');
const app = express();
//Load Pumlhorse
const pumlhorseExpress = require('pumlhorse-express')

//...

app.use(pumlhorseExpress.Router(require('./site.json')));

Route Configuration

The last line in the example above tells Pumlhorse to use a file named site.json for configuring routes. Here is an example configuration file.

{
    "routes": {
        "/api/animals": {
            "get": "api/animals/list.puml",
            "post": "api/animals/create.puml"
        },
        "/api/animals/:id": {
            "get": "api/animals/test.puml",
            "delete": "api/animals/delete.puml"
        },
        "/home": {
            "get": "ui/home.puml"
        }
    }
}

For example, a POST request to the route /api/animals will call the api/animals/create.puml script.

Request Parameters

In a script, you can access the request parameters

name: Sample controller for route /users/:userId
steps:
  # Retrieve request headers
  - log: Authorization is $headers.Authorization 
  # Retrieve route values with "path"
  - log: User id is $path.userId
  # Retrieve query string values with "query"
  - log: Query param is $query.myValue

If you are using the body-parser package, you can also retrieve the body with $body.

Returning Responses

The following functions are available for returning responses:

  • ok - Returns 200
  • created - Returns 201
  • accepted - Returns 202
  • noContent - Returns 204
  • badRequest - Returns 400
  • unauthorized - Returns 401
  • forbidden - Returns 403
  • notFound - Returns 404

These functions can be used as follows:

# Return a JSON response with status code 200
- ok:
    name: Horse
    weight: a lot
    color: Brown

Additionally, you can return other status codes:

# Return a JSON response with status code 123
- sendResponse:
    code: 123
    data:
      name: Horse
      weight: a lot
      color: Brown

Returning UI views

Pumlhorse supports returning HTML views. You can use whatever Express rendering engine you like.

- html:
    view: ./myView.jade
    data: # View model used for the view (if applicable)
      firstName: John
      lastName: Smith
      lastLogin: July 1st, 1997