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

raml-autoroute

v0.0.7

Published

Module to easily work with RAML1 specification in order to integrate dynamic checks, routing and controls in your API server implementation.

Downloads

13

Readme

raml-autoroute

Module to easily work with RAML1 specification in order to integrate dynamic checks, routing and controls in your API server implementation.

Installation

npm install raml-autoroute

Testing

cd /your/node/modules/path/raml-autoroute
npm install
npm test

Usage

Extracting all routes from a RAML

Getting all routes in an array extracted from a RAML1 file. You can check the RAML specification used for this example in the repository

var RamlAutoRoute = require('raml-autoroute')
var raml_definition_filepath = './raml/api.raml'

var auto_route = new RamlAutoRoute(raml_definition_filepath)
var routes_objects = auto_route.getRoutes()

console.log(JSON.stringify(routes_objects, null, 2))

/** output
[
    {
    "route_id": "GetTestrouteId",
    "verb": "get",
    "absoluteUri": "/{version}/testroute/{id}",
    "absoluteUriFull": "/v1/testroute/{id}",
    "controller_name": "TestrouteId",
    "express_uri": "/v1/testroute/:id"
    },
    {
    "route_id": "GetParamstestReadId",
    "verb": "get",
    "absoluteUri": "/{version}/paramstest/read/{id}",
    "absoluteUriFull": "/v1/paramstest/read/{id}",
    "controller_name": "ParamstestReadId",
    "express_uri": "/v1/paramstest/read/:id"
    }
]
*/

Extracting an example for a given route

Getting example for a route extracted from a RAML1 specification. You can check the RAML specification used for this example in the repository

var RamlAutoRoute = require('raml-autoroute')
var raml_definition_filepath = './raml/api.raml'

var auto_route = new RamlAutoRoute(raml_definition_filepath)

var route_id = 'GetTestrouteId'
var example = auto_route.getExample(route_id)

console.log(JSON.stringify(example, null, 2))

/** output
{
  "id": 1,
  "name": "Jean Dupont",
  "email": "[email protected]",
  "created_at": "2016-03-01T10:10:10Z",
  "updated_at": "2017-03-01T10:10:10Z"
}
*/

Extracting query parameters for a given route (unstable)

Getting query parameters for a route extracted from a RAML1 specification. You can check the RAML specification used for this example in the repository

var RamlAutoRoute = require('raml-autoroute')
var raml_definition_filepath = './raml/api.raml'

var auto_route = new RamlAutoRoute(raml_definition_filepath)

var route_id = 'GetTestrouteId'
var parameters = auto_route.getQueryParameters(route_id)

console.log(JSON.stringify(parameters, null, 2))

/** output
{
  "parameter1name": {
    "name": "parameter1name",
    "displayName": "String parameter",
    "typePropertyKind": "TYPE_EXPRESSION",
    "type": [
      "string"
    ],
    "example": "Value String parameter",
    "required": false,
    "description": "The String parameter",
    "structuredExample": {
      "value": "Value String parameter",
      "strict": true,
      "name": null,
      "structuredValue": "Value String parameter"
    }
  },
  "parameter2name": {
    "name": "parameter2name",
    "displayName": "number parameter",
    "typePropertyKind": "TYPE_EXPRESSION",
    "type": [
      "number"
    ],
    "example": 1984,
    "required": false,
    "description": "the number parameter",
    "structuredExample": {
      "value": "1984",
      "strict": true,
      "name": null,
      "structuredValue": 1984
    }
  },
  "parameterIsbn": {
    "name": "parameterIsbn",
    "displayName": "ISBN parameter",
    "typePropertyKind": "TYPE_EXPRESSION",
    "type": [
      "string"
    ],
    "example": "0321736079?",
    "required": false,
    "minLength": 10,
    "structuredExample": {
      "value": "0321736079?",
      "strict": true,
      "name": null,
      "structuredValue": "0321736079?"
    }
  }
}
*/