Code Monkey home page Code Monkey logo

osprey-resources's Introduction

Osprey Resources

NPM version NPM Downloads Build status Test coverage Greenkeeper badge

Iterate over RAML resources and generate a middleware router.

Installation

npm install osprey-resources --save

Usage

const express = require('express')
const resources = require('osprey-resources')
const utils = require('./utils')

const app = express()

// Array.<webapi-parser.EndPoint>
const endPoints = utils.getEndPoints()

app.use(resources(
  endPoints,
  function (method, path) {
    return function (req, res, next) {
      res.end('hello, world!')
    }
  }
))

The resources function accepts two arguments. The array of EndPoint objects from webapi-parser model and a function that will generate the route for that path. Return null if the route should not be used.

License

MIT license

osprey-resources's People

Contributors

blakeembrey avatar greenkeeper[bot] avatar greenkeeperio-bot avatar jstoiko avatar postatum avatar svc-scm avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

osprey-resources's Issues

An in-range update of osprey-router is breaking the build 🚨

The dependency osprey-router was updated from 0.6.0 to 0.6.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

osprey-router is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 8 commits.

  • 134bc4e 0.6.1
  • 15cb405 package lock
  • 1796b0e Sync package-lock
  • 2ed4444 Merge remote-tracking branch 'origin/greenkeeper/popsicle-10.0.0' into develop
  • 063157d Merge remote-tracking branch 'origin/greenkeeper/standard-12.0.0' into develop
  • 72fd8aa Update node version in travis
  • cb1d371 chore(package): update standard to version 12.0.0
  • ab34dde chore(package): update popsicle to version 10.0.0

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Possibility to add middleware(s) before the function that will generate the route for that path?

Hello,

I just wonder if there is not a possibility to add middleware(s) just before the handler function ...

I tried to mix the 2 osprey middlewares : https://github.com/mulesoft-labs/osprey-resources and https://github.com/mulesoft-labs/osprey-method-handler .
It doesn't seem to work together ..

I was thinking about something like that :

var express = require('express');
var resources = require('osprey-resources');
var app = express();
var handler = require('osprey-method-handler')
var connect = require('connect');

var router = resources(
  [{
    relativeUri: '/users',
    methods: [{
      method: 'post',
      body: {
        'application/json': {
          schema: '...'
        }
      }
    }]
  }],
function (method, path) {
      // the middleware(s)
      var chain = connect();
      var methodType = method.method.toUpperCase();
      chain.use(handler(method, path, methodType, {}))
      return chain;
 },
  function (method, path) {
    return function (req, res, next) {
      // the route
      res.end('hello, world!')
    }
  }
);

app.use('/v1' , router);

So, any idea ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.