Giter Site home page Giter Site logo

tree-soft / osprey-mock-service Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mulesoft-labs/osprey-mock-service

0.0 5.0 0.0 58 KB

Generate an API mock service from a RAML definition using Osprey

License: Other

JavaScript 97.01% RAML 2.99%

osprey-mock-service's Introduction

Osprey Mock Service

NPM version NPM downloads Build status Test coverage

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

Usage

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, http://example.com/api will result in http://localhost:{PORT}/api.

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

Options

  • -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 })
    app.use(osprey.server(raml))
    app.use(mockService(raml))
    app.listen(3000)
  })

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

Limitation

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.

License

Apache License 2.0

osprey-mock-service's People

Contributors

blakeembrey avatar jstoiko avatar janmesaric avatar greenkeeperio-bot avatar camiloforero avatar bambov avatar

Watchers

James Cloos avatar Andrey Vorobyev avatar Egor Zyuskin avatar  avatar  avatar

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.