Skip to content

Instantly share code, notes, and snippets.

@eaccmk
Created October 19, 2020 11:53
Show Gist options
  • Save eaccmk/0c361cb53ba869a3dbde4d86a8d501bb to your computer and use it in GitHub Desktop.
Save eaccmk/0c361cb53ba869a3dbde4d86a8d501bb to your computer and use it in GitHub Desktop.
Base64 Encoding Decoding Postman collection
{
"info": {
"_postman_id": "c23935f1-3640-45fd-adf2-0e342084262e",
"name": "Base64",
"description": "Some Interesting ause cases of Postman for making Day to Day live easier",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Base64__EN-CODING",
"event": [
{
"listen": "test",
"script": {
"id": "845ee2da-8c83-44ab-a73a-f108e194d5bc",
"exec": [
"const inputString = \"abcd1234\" ; // YWJjZDEyMzQ=",
"console.log(\"INPUT >> \",inputString,\" <<\");",
"",
"if(!inputString.length > 0) {",
" pm.test(\"FAIL \", () => {throw new Error(\" 'inputString' can not be empty !!\")});",
"}else{",
" try{",
" var wordArray = CryptoJS.enc.Utf8.parse(inputString);",
" var base64EncodedString = CryptoJS.enc.Base64.stringify(wordArray);",
" console.log(\"OUTPUT >> \",base64EncodedString,\" <<\");",
" pm.test(base64EncodedString,function(){});",
" }catch(e){",
" pm.test(\"FAIL\", () => {throw new Error(\"Malformed 'inputString', please verify the input again.\")});",
" }",
"}"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://medium.com/@eaccmk",
"protocol": "https",
"host": [
"medium",
"com"
],
"path": [
"@eaccmk"
]
},
"description": "INPUT : **Plain String** `inputString`\n\nOUTPUT : **Base64 encoded string** `base64EncodedString`\n Check results \n\n**TEST Tab** and\n**Console Section**"
},
"response": []
},
{
"name": "Base64__DE-CODING",
"event": [
{
"listen": "test",
"script": {
"id": "aba7ec13-8104-4e7b-ada8-c8a69ff0d4df",
"exec": [
"const base64EncodedString = \"YWJjZDEyMzQ=\" ; // abcd1234\r",
"console.log(\"INPUT >> \",base64EncodedString,\" <<\");\r",
"\r",
"if(!base64EncodedString.length > 0) {\r",
" pm.test(\"FAIL \", () => {throw new Error(\" 'base64EncodedString' can not be empty !!\")});\r",
"}else{\r",
" try{\r",
" var wordArray = CryptoJS.enc.Base64.parse(base64EncodedString);\r",
" var decodedString = CryptoJS.enc.Utf8.stringify(wordArray);\r",
" console.log(\"OUTPUT >> \",decodedString,\" <<\");\r",
" pm.test(decodedString,function(){});\r",
" }catch(e){\r",
" pm.test(\"FAIL\", () => {throw new Error(\"Malformed 'base64EncodedString', please verify the input again.\")});\r",
" }\r",
"}"
],
"type": "text/javascript"
}
}
],
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": "",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://medium.com/@eaccmk",
"protocol": "https",
"host": [
"medium",
"com"
],
"path": [
"@eaccmk"
]
},
"description": "INPUT : **Base64 encoded string** `base64EncodedString`\r\n\r\nOUTPUT : **Decoded Plain String** `decodedString`\r\n Check results \r\n\r\n**TEST Tab** and\r\n**Console Section**"
},
"response": []
}
],
"protocolProfileBehavior": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment