Giter Club home page Giter Club logo

apiary.syntax.js's Introduction

apiary.syntax.js

A javascript library that parses from/into apiary.io's syntax.
Inspired by apiary.io's language-templates.

Source code is written in coffee-script,
but the javascript counterpart can be compiled with coffee -c lib/apiary.syntax.coffee.

The library is a AMD/nodejs module with help from the UMD patterns.

Tests are will be run via nodeunit.

Basic Usage

var apiary = require('apiary');
var raw = [
    'POST /x?qwe=qwe',
    '> Accept: application/json',
    '{"qwe": "qwe"}',
    '< 200',
    '< Content-Type: application/json',
    '{"qwe": "qwe"}',
    '< 500',
    '< 404',
    '< Content-Type: application/json',
    'Not Found'
  ].join('\n');
var apiaryObj = apiary.fromRaw(raw);
console.log(apiaryObj);
/*
{
  "in": {
    "body": "{\"qwe\": \"qwe\"}",
    "headers": {
      "Accept": "application/json"
    }
  },
  "method": "POST",
  "outs": [
    {
      "body": "{\"qwe\": \"qwe\"}",
      "headers": {
        "Content-Type": "application/json"
      },
      "status": "200"
    },
    {
      "status": "500"
    },
    {
      "body": "Not Found",
      "headers": {
        "Content-Type": "application/json"
      },
      "status": "404"
    }
  ],
  "URI": "http://localhost/x?qwe=qwe"
}*/
console.log(apiary.toRaw(apiaryObj));
/*
POST http://localhost/x?qwe=qwe
> Accept: application/json
{"qwe": "qwe"}
< 200
< Content-Type: application/json
{"qwe": "qwe"}
< 500
< 404
< Content
*/
console.log(apiary.toCurl(apiaryObj));
/*
curl\
  --include\
  --request POST\
  --url http://localhost/x?qwe=qwe\
  --header "Accept: application/json"\
  --data "{"qwe": "qwe"}"
*/
console.log(apiary.toKurl(apiaryObj));
/*
kurl\
  --include\
  --request POST\
  --url http://localhost/x\
  --query qwe=qwe\
  --header "Accept: application/json"\
  --data-json qwe="qwe"
*/
console.log(apiary.toJQuery(apiaryObj));
/*
// jQuery 1.6+
$.ajax({
  "data": "{\"qwe\": \"qwe\"}",
  "headers": {
    "Accept": "application/json",
    "Content-Length": "14"
  },
  "type": "POST",
  "url": "http://localhost/x?qwe=qwe"
}).always(function(data, textStatus, jqXHR){console.log(data, textStatus, jqXHR.statusText, jqXHR.status, jqXHR)});
*/

Comprehensive Usage

TODO

apiary.syntax.js's People

Contributors

andreineculau avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

apiary.syntax.js's Issues

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.