Coder Social home page Coder Social logo

farolfo / raml-server Goto Github PK

View Code? Open in Web Editor NEW
160.0 15.0 31.0 18 KB

run a mocked server JUST based on a RAML API's definition .. zero coding

License: MIT License

JavaScript 53.86% RAML 46.14%
raml swagger api mock ui raml-server json-server json-schema

raml-server's Introduction

RAML Server

Get a full fake REST API with zero coding by writing a RAML spec.

Why building a new RAML based server? Cause this one works with JSON-Server, so no much code to do (maintain).

This is an open source project, so issues, PRs and suggestions are wellcome.

Install

RAML Server is tested under node v0.12. If you don't have node installed yet, doing it via nvm is recommended.

If you have node installed, run

$ npm install -g raml-server

Usage

Start a server based on the exampleApi.raml file

$ raml-server exampleApi.raml

And hit localhost:3000/songs. Also, later POSTs to /songs on the server will be saved!

How it works?

This is done by generating responses' data reading the JSON schemas with the RAML Mocker, and run with JSON-Server.

Next release fixes

  • Support imports in RAML.
  • Support nested resources (today it only routes the JSON schema of the top level resources, like /songs).
  • RAML 1.0.
  • Start a server based on the api.raml file that is on the current directory if no argument is provided.

As seen at

raml-server's People

Contributors

alexandrebodin avatar alexeytokar avatar androa avatar bryant1410 avatar farolfo avatar jabher avatar jastrzebowski avatar

Stargazers

 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

Watchers

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

raml-server's Issues

One resource method without example will break whole mock

Following RAML will cause raml-server to fail (i've added responses and 204 for delete method):

#%RAML 0.8

title: World Music API
baseUri: http://example.api.com/{version}
version: v1

/songs:
  get:
    queryParameters:
      genre:
        description: filter the song by genre
  post:
  /{songId}:
    get:
      responses:
        200:
          body:
            application/json:
              schema: |
                { "$schema": "http://json-schema.org/schema",
                  "type": "object",
                  "description": "A canonical song",
                  "properties": {
                    "title": { "type": "string" },
                    "artist": { "type": "string"}
                  },
                  "required": [ "title", "artist" ]
                }
    delete:
      description: |
        This method will *delete* an **individual song**
      responses:
        204:

It will work, if i also specify following code for delete method:

body:
  application/json:
    example: ""

So.. i would propose to trait methods without examples like empty ones or just skip them, but warn user about it on start.

post request

Code that we can use to post a song will be very helpful. Can you please provide that so I can test the server with post requests?

Limitation with single RAML file

Do you have intention of solving the single file limitation of the Raml-Server? Also it will be better if implemented as a module.

SyntaxError when using RAML tutorial example (parameters not supported?)

Hi guys,

I'm trying to use the raml-server with the example given in the RAML official 200 tutorial (http://raml.org/developers/raml-200-tutorial), jukebox-api.raml.

I get the following error:

$ raml-server jukebox-api.raml 
Error parsing: SyntaxError: Unexpected token <

Does it mean that raml-server doesn't support parameters (<< resourcePathName >>, ...) as explained in http://raml.org/developers/raml-200-tutorial#parameters ?
Or do I miss something?

can not install in node6.9.0

npm ERR! node v6.9.0
npm ERR! npm v3.10.8

npm ERR! shasum check failed for /var/folders/k4/9bkz633525d0xjdghft_b3f80000gn/T/npm-6176-d060d5f6/registry.npmjs.org/faker/-/faker-3.1.0.tgz
npm ERR! Expected: 0f908faf4e6ec02524e54a57e432c5c013e08c9f
npm ERR! Actual: 4424c6a2142e4bb653fcb78a886a1f0b23cd391d
npm ERR! From: https://registry.npmjs.org/faker/-/faker-3.1.0.tgz

RAML 1.0 support

Planning support for RAML 1.0? Is this still being maintained?

Thanks.

Can't get it to work

I installed it locally (w/o the -g option).
Then run it as: raml-server path-to-raml-file/api.raml

Then hitting the top level resources at http://localhost:3000/top-level-resources always returns empty object {}, while the server logs reports 404. I made sure that my raml file has no include (only a single file), and has a schema defined for the response.

I tried with your exampleApi.raml, and hit http://localhost:3000/songs, got same result (404). In any case, if I hit the base url http://localhost:3000/, a successful page is returned with the first sentence "Congrats! You're successfully running JSON Server".

Any idea?

Thanks.

Error parsing RAML with included raml schemas

Error got from cli:

# raml-server api.raml
Error parsing: while validating body
schema must be a string
  in "api.raml", line 28, column 13:
                schema: !include responses/BaseOk ...

api.raml file contents:

#%RAML 0.8
title: test for Error parsing
version: v1
protocols: [HTTP, HTTPS]

baseUri: http://{host}:{port}/{version}
baseUriParameters:
  host:
    displayName: Domain name / IP address
    type: string
    default: localhost
  port:
    displayName: Port
    type: string
    default: 80


mediaType: application/json

/:
  get:
    description: "Base request"
    responses:
      200:
        description: "Base request description"
        body:
          application/json:
            schema: !include responses/BaseOk.raml

responses/BaseOk.raml file contents:

description: "Base OK result."

Error: EISDIR: illegal operation on a directory, read

I get a lot of following errors on start:

{ [Error: EISDIR: illegal operation on a directory, read] errno: -21, code: 'EISDIR', syscall: 'read' }
{ [Error: EISDIR: illegal operation on a directory, read] errno: -21, code: 'EISDIR', syscall: 'read' }
{ [Error: EISDIR: illegal operation on a directory, read] errno: -21, code: 'EISDIR', syscall: 'read' }

What can be the issue?

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.