Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Most end points you write will provide some type of output back to the user.  The metadata around output entity definitions is very similar to input entity definitions.  Output entity definitions are flat structures that cannot contain complex types like other objects.  The framework always takes the last piece output returned by the business logic of the end point and maps it into your output entity definition.  This is a core feature of the framework.  Mapping business logic output to output entity objects is handled by implementations of Endpoints.IOutputMapper.  Out of the box, we support mapping DataTables and GEs into the output for an end pointendpoint.  

The output entity definition can have the following properties:

Info
titleOutput Entity Definition properties

TODO double check the input entity definition fields against the interface, I think im missing some items.

Property NameValue

Description

Namestring

A unique identifier for this output entity definition. The identifier must be unique within the entire Endpoint.json definition file.

DescriptionstringA description for this payload that will be surfaced in the public API documentation.
IsCollectionboolIndicates whether or not the output of this payload is a collection of objects or a single object.
FieldsobjectWithin the value object each property name is the expected output field name. That property's value is a Field Object (described below).
Info
titleField Object properties

The fields field's property on the output entity definition should be an object value. Each property on the object should be the expected output field name. That property's value should be an object with the following properties:

Property NameValueDescription
TypestringDescribes what type the framework should expect for the output field. Valid types are string, int, integer, long, decimal, bool, boolean, date, datetime, array and double.
DescriptionstringA description for this field that will be surfaced in the public API documentation.
SourceFieldstringIf the output payload is a GE, this value allows you to automatically map public facing fields to backend fields.

...

Code Block
languagejs
{
  "endpoints": {             
    "ExamplesGetSingleProduct": {
      "outputEntityDefinition": {
        "name": "ExampleProductOutput",
        "fields": {
          "id": {
            "type": "long"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string",
            "description": "A plain text description of the product."
          },
          "hasComplexPricing": {
            "type": "boolean",
            "description": "If true, this indicates you must add the product to the cart in order to get an accurate price."
          },
          "defaultPrice": {
            "type": "decimal"
          }    
      }
      //remaining metadata omitted
    }
  }
}

If our end point endpoint was to get a collection of products, such as GET /examples/products/, we could define the output this way instead:

...

Often you will want to define a collection based end point endpoint like GET /examples/products and a singular resource end point endpoint like GET /examples/products/{productId}.  It is possible to avoid duplicating most of the output entity definition metadata using references.  

...