Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Format pair of HTTP Request and Response to API Blueprint format

License

Notifications You must be signed in to change notification settings

apiaryio/api-blueprint-http-formatter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTTP API Blueprint formater

Build Status Dependency Status devDependency Status

Usage

It accepts object with request and response keys in format used by Gavel and returns it back in API Blueprint format

Example usage

var bf = require('./src/api-blueprint-http-formatter');
var post = {
  "request": {
    "method": "POST",
    "uri": "/shopping-cart",
    "headers": {
      "User-Agent": "curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5",
      "Host": "curltraceparser.apiary.io",
      "Accept": "*/*",
      "Content-Type": "application/json",
      "Content-Length": "39"
    },
    "body": "{ \"product\":\"1AB23ORM\", \"quantity\": 2 }"
  },
  "response": {
    "statusCode": "201",
    "statusMessage": "Created",
    "headers": {
      "Content-Type": "application/json",
      "Date": "Sun, 21 Jul 2009 14:51:09 GMT",
      "X-Apiary-Ratelimit-Limit": "120",
      "X-Apiary-Ratelimit-Remaining": "119",
      "Content-Length": "50",
      "Connection": "keep-alive"
    },
    "body": "{ \"status\": \"created\", \"url\": \"/shopping-cart/2\" }"
  }
};

blueprint = bf.format(post);
console.log(blueprint);

Output is a API Blueprint

# POST /shopping-cart
+ Request
    + Headers

            User-Agent:curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5
            Host:curltraceparser.apiary.io
            Accept:*/*
            Content-Type:application/json
            Content-Length:39

    + Body

            { "product":"1AB23ORM", "quantity": 2 }

+ Response 201
    + Headers

            Content-Type:application/json
            Date:Sun, 21 Jul 2009 14:51:09 GMT
            X-Apiary-Ratelimit-Limit:120
            X-Apiary-Ratelimit-Remaining:119
            Content-Length:50
            Connection:keep-alive

    + Body

            { "status": "created", "url": "/shopping-cart/2" }

Use Protagonist, Api Blueprint Node.js parser to parse or canonical Snowcrash parser to get Blueprint AST

API Reference

format(pair) - returns string with message pair in API blueprint format

About

Format pair of HTTP Request and Response to API Blueprint format

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published