node package manager
Love JavaScript? Your insights can make it even better. Take the 2017 JavaScript Ecosystem Survey »


Osprey Mock Service

NPM version NPM downloads Build status Test coverage

Generate an API mock service from a RAML definition using Osprey.


Global (CLI)

npm install -g osprey-mock-service

Start the service from the CLI. This will automatically use the baseUri as the path to the mock service. For example, will result in http://localhost:{PORT}/api.

osprey-mock-service -f api.raml -p 3000


  • -f Path to the root RAML definition (E.g. /path/to/api.raml)
  • -p Port number to bind the server locally

Locally (JavaScript)

npm install osprey-mock-service --save

The mocking service simply accepts a RAML definition and returns a router that can be mounted into any Connect-style middleware layer or even used with http. Best used with osprey to support incoming validation automatically.

var mockService = require('../osprey-mock-service')
var express = require('express')
var parser = require('raml-1-parser')
var path = require('path')
var osprey = require('osprey')
var app = express()
parser.loadRAML(path.join(__dirname, 'api.raml'), { rejectOnErrors: true })
  .then(function (ramlApi) {
    var raml = ramlApi.expand(true).toJSON({ serializeMetadata: false })

Additional methods

  • createServer Creates a mock service instance with Osprey
  • createServerFromBaseUri Creates a mock service with Osprey and uses the base URI path
  • loadFile Creates a mock service with Osprey and the base URI path from a RAML file


RAML 1.0

This module only uses the example (or examples) property inside a given resource/method body. It does not take into consideration any of the example properties defined inside the properties or schema of the body itself.


Apache License 2.0