Template engine (v1)

http://api.example.com/{version}

Table of contents

mod-template-engine API

This module dedicated for storing templates and generating text, html, xml, doc, docx etc from the template.

/templates

POST /templates

Add a new template

POST /templates
Body

Media type: application/json

Type: json

Content:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "description": "Template",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "description": "Template id"
    },
    "description": {
      "type": "string",
      "description": "Template description"
    },
    "outputFormats": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Array of output formats"
    },
    "templateResolver": {
      "type": "string",
      "description": "Template engine name"
    },
    "localizedTemplates": {
      "type": "object",
      "description": "List of localized templates",
      "additionalProperties": {
        "type": "object",
        "description": "Template content",
        "$ref": "templateContent.json"
      }
    },
    "metadata": {
      "type" : "object",
      "$ref" : "raml-util/schemas/metadata.schema"
    }
  },
  "required": [
    "templateResolver",
    "localizedTemplates",
    "outputFormats",
    "description"
  ]
}

Response 201

Body

Media type: application/json

Type: json

Content:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "description": "Template",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "description": "Template id"
    },
    "description": {
      "type": "string",
      "description": "Template description"
    },
    "outputFormats": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Array of output formats"
    },
    "templateResolver": {
      "type": "string",
      "description": "Template engine name"
    },
    "localizedTemplates": {
      "type": "object",
      "description": "List of localized templates",
      "additionalProperties": {
        "type": "object",
        "description": "Template content",
        "$ref": "templateContent.json"
      }
    },
    "metadata": {
      "type" : "object",
      "$ref" : "raml-util/schemas/metadata.schema"
    }
  },
  "required": [
    "templateResolver",
    "localizedTemplates",
    "outputFormats",
    "description"
  ]
}

Response 400

Bad request

Body

Media type: text/plain

Type: any

Example:

Bad request

Response 422

Validation errors

Body

Media type: application/json

Type: json

Content:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "errors": {
      "id": "errors",
      "type": "array",
      "items": {
        "type": "object",
        "$ref": "error.schema"
      }
    },
    "total_records": {
      "type": "integer"
    }
  }
}

Example:

{
  "errors": [
    {
      "message": "may not be null",
      "type": "1",
      "code": "-1",
      "parameters": [
        {
          "key": "moduleTo",
          "value": "null"
        }
      ]
    }
  ]
}

Response 500

Internal server error

Body

Media type: text/plain

Type: any

Example:

Internal server error

GET /templates

Get a list of templates

GET /templates
Query Parameters
  • offset: (integer - default: 0 - minimum: 0 - maximum: 2147483647)

    Skip over a number of elements by specifying an offset value for the query

    Example:

    0
  • limit: (integer - default: 10 - minimum: 0 - maximum: 2147483647)

    Limit the number of elements returned in the response

    Example:

    10
  • query: (string)

    A query string to filter templates based on matching criteria in fields.

Response 200

Body

Media type: application/json

Type: json

Content:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "description": "Collection of templates",
  "properties": {
    "templates": {
      "type": "array",
      "description": "List of templates",
      "items": {
        "type": "object",
        "$ref": "template.json"
      }
    },
    "totalRecords": {
      "type": "integer"
    }
  },
  "required": [
    "templates",
    "totalRecords"
  ]
}

Response 400

Bad request

Body

Media type: text/plain

Type: any

Example:

Bad request

Response 500

Internal server error

Body

Media type: text/plain

Type: any

Example:

Internal server error

GET /templates/{templateId}

Get template by id

GET /templates/{templateId}
URI Parameters
  • templateId: required (string)

Response 200

Body

Media type: application/json

Type: json

Content:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "description": "Template",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "description": "Template id"
    },
    "description": {
      "type": "string",
      "description": "Template description"
    },
    "outputFormats": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Array of output formats"
    },
    "templateResolver": {
      "type": "string",
      "description": "Template engine name"
    },
    "localizedTemplates": {
      "type": "object",
      "description": "List of localized templates",
      "additionalProperties": {
        "type": "object",
        "description": "Template content",
        "$ref": "templateContent.json"
      }
    },
    "metadata": {
      "type" : "object",
      "$ref" : "raml-util/schemas/metadata.schema"
    }
  },
  "required": [
    "templateResolver",
    "localizedTemplates",
    "outputFormats",
    "description"
  ]
}

Response 404

Template not found

Body

Media type: text/plain

Type: any

Example:

Template not found

Response 500

Internal server error

Body

Media type: text/plain

Type: any

Example:

Internal server error

PUT /templates/{templateId}

Modify a template

PUT /templates/{templateId}
URI Parameters
  • templateId: required (string)
Body

Media type: application/json

Type: json

Content:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "description": "Template",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "description": "Template id"
    },
    "description": {
      "type": "string",
      "description": "Template description"
    },
    "outputFormats": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Array of output formats"
    },
    "templateResolver": {
      "type": "string",
      "description": "Template engine name"
    },
    "localizedTemplates": {
      "type": "object",
      "description": "List of localized templates",
      "additionalProperties": {
        "type": "object",
        "description": "Template content",
        "$ref": "templateContent.json"
      }
    },
    "metadata": {
      "type" : "object",
      "$ref" : "raml-util/schemas/metadata.schema"
    }
  },
  "required": [
    "templateResolver",
    "localizedTemplates",
    "outputFormats",
    "description"
  ]
}

Response 200

Body

Media type: application/json

Type: json

Content:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "description": "Template",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "description": "Template id"
    },
    "description": {
      "type": "string",
      "description": "Template description"
    },
    "outputFormats": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Array of output formats"
    },
    "templateResolver": {
      "type": "string",
      "description": "Template engine name"
    },
    "localizedTemplates": {
      "type": "object",
      "description": "List of localized templates",
      "additionalProperties": {
        "type": "object",
        "description": "Template content",
        "$ref": "templateContent.json"
      }
    },
    "metadata": {
      "type" : "object",
      "$ref" : "raml-util/schemas/metadata.schema"
    }
  },
  "required": [
    "templateResolver",
    "localizedTemplates",
    "outputFormats",
    "description"
  ]
}

Response 404

Template not found

Body

Media type: text/plain

Type: any

Example:

Template not found

Response 500

Internal server error

Body

Media type: text/plain

Type: any

Example:

Internal server error

DELETE /templates/{templateId}

Delete template by id

DELETE /templates/{templateId}
URI Parameters
  • templateId: required (string)

Response 204

Body

Media type: text/plain

Type: any

Response 404

Template not found

Body

Media type: text/plain

Type: any

Example:

Template not found

Response 500

Internal server error

Body

Media type: text/plain

Type: any

Example:

Internal server error

/template-request

POST /template-request

process specified template using given context

POST /template-request
Body

Media type: application/json

Type: json

Content:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "description": "Request for template processing",
  "type": "object",
  "properties": {
    "templateId": {
      "type": "string",
      "description": "Target template id"
    },
    "lang": {
      "type": "string",
      "description": "Target template language"
    },
    "outputFormat": {
      "type": "string",
      "description": "Output format"
    },
    "context": {
      "type": "object",
      "description": "Context object"
    }
  },
  "required": [
    "templateId",
    "lang",
    "outputFormat"
  ],
  "additionalProperties": false
}

Response 200

Body

Media type: application/json

Type: json

Content:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "description": "Result of template processing",
  "type": "object",
  "properties": {
    "templateId": {
      "type": "string",
      "description": "Source template id"
    },
    "result": {
      "type": "object",
      "description": "Template processing output",
      "$ref": "templateContent.json"
    },
    "meta": {
      "type": "object",
      "description": "Template output metadata",
      "properties": {
        "size": {
          "type": "integer",
          "description": "Size of output in bytes"
        },
        "dateCreate": {
          "type": "string",
          "format": "date-time",
          "description": "Date of template processing"
        },
        "lang": {
          "type": "string",
          "description": "Processed template language"
        },
        "outputFormat": {
          "type": "string",
          "description": "Output format"
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}

Response 400

Body

Media type: text/plain

Type: any

Example:

Bad request

Response 422

Validation errors

Body

Media type: application/json

Type: json

Content:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "errors": {
      "id": "errors",
      "type": "array",
      "items": {
        "type": "object",
        "$ref": "error.schema"
      }
    },
    "total_records": {
      "type": "integer"
    }
  }
}

Example:

{
  "errors": [
    {
      "message": "may not be null",
      "type": "1",
      "code": "-1",
      "parameters": [
        {
          "key": "moduleTo",
          "value": "null"
        }
      ]
    }
  ]
}

Response 500

Body

Media type: text/plain

Type: any

Example:

Internal server error