Last active
September 17, 2018 12:41
-
-
Save letzya/7df4dbc37f2f075795995efb8e205d3e to your computer and use it in GitHub Desktop.
Demo body transform of response, XML to JSON using petstore's endpoint /pet/{id}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Import to Tyk swagger petstore as an api. | |
2. In the endpoint designer, under endpoint /pet/{id} add the `body transform plugin | |
3. Click on respose | |
4. Paste this template | |
{ | |
"category": { | |
"id": {{.Pet.category.id}}, | |
"name": "{{.Pet.category.name}}" | |
}, | |
"id": {{.Pet.id}}, | |
"name": {{.Pet.name}}, | |
"photoUrls": [ | |
{{.Pet.photoUrls.photoUrl}} | |
], | |
"status": {{.Pet.status}}, | |
"tags": [ | |
{ | |
"id": {{.Pet.tags.tag.id}}, | |
"name": {{.Pet.tags.tag.name}} | |
} | |
] | |
} | |
3. Tested it on the UI with the output from calling the endpoint on petstore directly: | |
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Pet><category><id>1</id><name>string</name></category><id>1</id><name>doggie</name><photoUrls><photoUrl>string</photoUrl></photoUrls><status>available</status><tags><tag><id>1</id><name>string</name></tag></tags></Pet> | |
4. Save | |
5. Tested the api: | |
yaara@Yaara's Mac ~ (conf-files) $ curl http://www.tyk-gateway.com:8080/petstore/pet/1 -H "Accept: application/xml" | |
{ | |
"category": { | |
"id": 1, | |
"name": "string" | |
}, | |
"id": 1, | |
"name": dingdang, | |
"photoUrls": [ | |
http:// | |
], | |
"status": available, | |
"tags": [ | |
{ | |
"id": 1, | |
"name": string | |
} | |
] | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment