RAML goodies for Javascript
Last updated 6 years ago by pateketrueke .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install raml4js 
SYNC missed versions from official npm registry.

Build Status NPM version Coverage Status

Under the hood raml4js uses the extraordinary raml-parser to load your RAML:

var fs = require('fs'),
    raml4js = require('raml4js');

raml4js('/path/to/api.raml', function(err, data) {
  if (err) {
    // raml-parser errors
  } else {
    // api-client generation for free
    var overrides = { baseUri: 'http://api.other-site.com/{version}' },
        factory = raml4js.client(data),
        client = factory(overrides);

    // save the client factory as CommonJS module
    fs.writeFileSync('/path/to/api-client.js', 'module.exports = ' + factory.toString() + ';');

    // or use the api-client created directly
    // client.resources.path.to.resource.get();


Since 0.2.1 you can install raml4js globally:

$ npm install -g raml4js
$ raml4js path/to/api.raml > client.js

Use raml4js -h to see full usage info.


  • raml4js(file, callback)

  • raml4js.read(file, callback)

    Will parse the RAML file and then will invoke the callback(err, data) function.

    If no error occurs data will contain the parsed RAML as object, otherwise err will be fulfilled.

  • raml4js.client(data, class_name)

    Generate static code using data as RAML object input.

    Will use class_name for the client instance, defaults to APIClient.

Since 0.2.0 the method validate() was deprecated in favor of ramlev.

Client usage

The generated client isn't capable to perform any request, you're encouraged to provide a wrapper for this using the requestHandler method:

var http = require('http-api-client'),
    client = require('/path/to/api-client.js')();

client.requestHandler(function(method, request_url, request_options) {
  return http.request({
    method: method,
    url: request_url,
    parameters: request_options.data

If you have a resource like GET /articles/{articleId}, then:

client.resources.articles.articleId(1).get().then(function(response) {

Yet another RAML client generator?

Yes, there's an official raml-client-generator for full-featured Javascript clients.

Since raml4js doesn't ship any dependency you can use fetch() or even jQuery's $.ajax for.

Current Tags

  • 0.3.0                                ...           latest (6 years ago)

1 Versions

  • 0.3.0                                ...           6 years ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (5)
Dev Dependencies (2)

Copyright 2014 - 2016 © taobao.org |