Beispiel für Nachrichtenartikel (API Gateway-Modelle und -Mapping-Vorlagen)
In den folgenden Abschnitten finden Sie Beispiele für Modelle und Mapping-Vorlagen, die für eine Beispiel-Nachrichtenartikel-API in Amazon API Gateway verwendet werden könnten. Weitere Informationen über Modelle und Mapping-Vorlagen in API Gateway finden Sie unter Arbeiten mit Modellen und Mapping-Vorlagen.
Themen
- Originaldaten (Beispiel für Nachrichtenartikel)
- Eingabemodell (Beispiel für Nachrichtenartikel)
- Eingabe-Mapping-Vorlage (Beispiel für Nachrichtenartikel)
- Umgewandelte Daten (Beispiel für Nachrichtenartikel)
- Ausgabemodell (Beispiel für Nachrichtenartikel)
- Ausgabe-Mapping-Vorlage (Beispiel für Nachrichtenartikel)
Originaldaten (Beispiel für Nachrichtenartikel)
Nachstehend finden Sie die ursprünglichen JSON-Daten für das Nachrichtenartikel-Beispiel:
{ "count": 1, "items": [ { "last_updated_date": "2015-04-24", "expire_date": "2016-04-25", "author_first_name": "John", "description": "Sample Description", "creation_date": "2015-04-20", "title": "Sample Title", "allow_comment": "1", "author": { "last_name": "Doe", "email": "johndoe@example.com", "first_name": "John" }, "body": "Sample Body", "publish_date": "2015-04-25", "version": "1", "author_last_name": "Doe", "parent_id": 2345678901, "article_url": "http://www.example.com/articles/3456789012" } ], "version": 1 }
Eingabemodell (Beispiel für Nachrichtenartikel)
Nachstehend finden Sie das Eingabemodell, das den ursprünglichen JSON-Daten für das Nachrichtenartikel-Beispiel entspricht:
{ "$schema": "http://json-schema.org/draft-04/schema#", "title": "NewsArticleInputModel", "type": "object", "properties": { "count": { "type": "integer" }, "items": { "type": "array", "items": { "type": "object", "properties": { "last_updated_date": { "type": "string" }, "expire_date": { "type": "string" }, "author_first_name": { "type": "string" }, "description": { "type": "string" }, "creation_date": { "type": "string" }, "title": { "type": "string" }, "allow_comment": { "type": "string" }, "author": { "type": "object", "properties": { "last_name": { "type": "string" }, "email": { "type": "string" }, "first_name": { "type": "string" } } }, "body": { "type": "string" }, "publish_date": { "type": "string" }, "version": { "type": "string" }, "author_last_name": { "type": "string" }, "parent_id": { "type": "integer" }, "article_url": { "type": "string" } } } }, "version": { "type": "integer" } } }
Eingabe-Mapping-Vorlage (Beispiel für Nachrichtenartikel)
Nachstehend finden Sie die Mapping-Vorlage, die den ursprünglichen JSON-Daten für das Nachrichtenartikel-Beispiel entspricht:
#set($inputRoot = $input.path('$')) { "count": $inputRoot.count, "items": [ #foreach($elem in $inputRoot.items) { "last_updated_date": "$elem.last_updated_date", "expire_date": "$elem.expire_date", "author_first_name": "$elem.author_first_name", "description": "$elem.description", "creation_date": "$elem.creation_date", "title": "$elem.title", "allow_comment": "$elem.allow_comment", "author": { "last_name": "$elem.author.last_name", "email": "$elem.author.email", "first_name": "$elem.author.first_name" }, "body": "$elem.body", "publish_date": "$elem.publish_date", "version": "$elem.version", "author_last_name": "$elem.author_last_name", "parent_id": $elem.parent_id, "article_url": "$elem.article_url" }#if($foreach.hasNext),#end #end ], "version": $inputRoot.version }
Umgewandelte Daten (Beispiel für Nachrichtenartikel)
Im Folgenden finden Sie ein Beispiel dafür, wie die ursprünglichen JSON-Daten des Nachrichtenartikel-Beispiels zur Ausgabe umgewandelt werden könnten:
{ "count": 1, "items": [ { "creation_date": "2015-04-20", "title": "Sample Title", "author": "John Doe", "body": "Sample Body", "publish_date": "2015-04-25", "article_url": "http://www.example.com/articles/3456789012" } ], "version": 1 }
Ausgabemodell (Beispiel für Nachrichtenartikel)
Im Folgenden sehen Sie das Ausgabemodell, das dem umgewandelten JSON-Datenformat entspricht:
{ "$schema": "http://json-schema.org/draft-04/schema#", "title": "NewsArticleOutputModel", "type": "object", "properties": { "count": { "type": "integer" }, "items": { "type": "array", "items": { "type": "object", "properties": { "creation_date": { "type": "string" }, "title": { "type": "string" }, "author": { "type": "string" }, "body": { "type": "string" }, "publish_date": { "type": "string" }, "article_url": { "type": "string" } } } }, "version": { "type": "integer" } } }
Ausgabe-Mapping-Vorlage (Beispiel für Nachrichtenartikel)
Im Folgenden sehen Sie die Ausgabe-Mapping-Vorlage, die dem umgewandelten JSON-Datenformat entspricht. Die Vorlagenvariablen hier basieren auf dem nicht umgewandelten Original-JSON-Datenformat:
#set($inputRoot = $input.path('$')) { "count": $inputRoot.count, "items": [ #foreach($elem in $inputRoot.items) { "creation_date": "$elem.creation_date", "title": "$elem.title", "author": "$elem.author.first_name $elem.author.last_name", "body": "$elem.body", "publish_date": "$elem.publish_date", "article_url": "$elem.article_url" }#if($foreach.hasNext),#end #end ], "version": $inputRoot.version }