jamztang
11/2/2011 - 3:31 PM

damn-api sample spec

damn-api sample spec

{
  "host": ["api.example.com", "api-staging.example.com"],
  "headers": { // By default, optional: false
    "X-EXAMPLE-DEVICE-TYPE": ["iphone", "android"],
    "X-EXAMPLE-DEVICE-UUID": {
      "value": "mock",
      "optional": true
    },
    "X-EXAMPLE-APP-ID": ["com.example.iphone.app1", "com.example.iphone.app2", "com.example.android.app1"]
  },
  "api_groups": [
    {
      "name": "Account API",
      "apis": [
        {
          "name": "Account Registration",
          "type": "json",  // Response Type
          "path": "/api/v1/account/register.json",
          "method": "POST",
          "body": {  // Need to consider body type - form-data, json, ...
            "user[username]": "*",  // Text Field for free input
            "user[password]": "*",
            "user[password_confirmation]": "*"
          }
        },
        {
           "name": "Get Account Info",
           "type": "json",
           "path": "/api/v1/account/profile.json",
           "method": "GET",
           "headers": {  // Merge with or Override global headers config
             "X-EXAMPLE-AUTH-TOKEN": "mock"  // Only one fixed value
           }
        }
      ]
    }, 
    { // Another API Group
      "name": "Articles API",
      "apis": [
        {
          "name": "Get New Article Form",
          "type": "web",  // Render WebView
          "path": "/api/v1/articles/new",
          "method": "GET"
        },
        {
          "name": "List Articles",
          "type": "json",
          "path": "/api/v1/articles.json",
          "method": "GET",
          "params": { // URL Params, i.e. /api/v1/articles.json?page=1&per_page=15
            "page": "\d", // Free input, but Integer only
            "per_page": {
              "value": "\d",
              "optional": true
            }
          }
        }
      ]
    }
  ]
}