\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Giang.nd2508} \pdfinfo{ /Title (postman-script-1.pdf) /Creator (Cheatography) /Author (Giang.nd2508) /Subject (Postman Script 1 Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{D49090} \definecolor{LightBackground}{HTML}{F9F1F1} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Postman Script 1 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Giang.nd2508} via \textcolor{DarkBackground}{\uline{cheatography.com/134606/cs/27793/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Giang.nd2508 \\ \uline{cheatography.com/giang-nd2508} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 3rd May, 2021.\\ Updated 25th February, 2023.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Data Type}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{String}}: chứa các ký tự. Ví dụ "hello"} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Number}}: là số nguyên hoặc thập phân. Ví dụ 20, 32.46} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Array}}: chứa nhiều phần tử, các phần tử có thể cùng hoặc không cùng kiểu dữ liệu} \tn % Row Count 6 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Object}}: gồm các cặp key-value} \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Boolean}}: true hoặc false} \tn % Row Count 8 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Null}}: thể hiện rằng biến đó không trỏ đến bất kỳ object nào} \tn % Row Count 10 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{String}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{let s1 = "Hello World"; \newline s1.length; // 11 \newline s1.indexOf("l"); // 2 \newline s1.repeat(4); // Hello WorldHello WorldHello WorldHello World \newline s1.toLowerCase(); // hello world \newline s1.toUpperCase(); //HELLO WORLD \newline s1.slice(0, s1.indexOf("o")); // Hell \newline \newline let s2 = "100.332"; \newline let num1 = parseInt(s2) + 10; // 110 \newline let num2 = parseFloat(s2) + 10; // 110.332} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Number}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{let num1 = 100; \newline let num2 = 0.5; \newline let num3 = num1 + num2; // 100.5 \newline let num4 = num1 - num2; // 99.5 \newline let num5 = num1 * num2; // 50 \newline let num6 = num1 / num2; // 200 \newline \newline let s1 = num1.toString(); \newline console.log(s1.repeat(3)); // 100100100} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Object}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{const obj1 = \{ \newline "data": \{ \newline "name": "lucas", \newline "age": 20, \newline "is\_admin": true \newline \}, \newline "string": "Hi" \newline \}; \newline \newline // Access value \newline let name = obj1.data.name; \newline let age = obj1.data{[}"age"{]}; \newline \newline // Add key-value \newline obj1.new\_key = "new key here"; \newline \newline // Edit value \newline obj1.data.is\_admin = false; \newline \newline // Delete key \newline delete obj1.string; \newline \newline // Copy object \newline let obj2 = \seqsplit{JSON.parse(JSON.stringify(obj1));}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Array}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{const arr = {[}"english", "german", "french", "spanish"{]}; \newline \newline // Get value \newline let first = arr{[}0{]}; \newline let last = arr{[}arr.length - 1{]}; \newline \newline // Add item \newline arr.push("last\_item\_1", "last\_item\_2"); //at the end \newline arr.unshift("first\_item\_1", "first\_item\_2"); //at the beginning \newline \newline // Edit value \newline arr{[}4{]} = "edit value"; \newline \newline // Remove item \newline let another\_last = arr.pop(); //remove last item of array \newline let another\_first = arr.shift(); //remove first item of array \newline \newline // Query index of value \newline let position = arr.indexOf("english"); \newline \newline // From position 0, delete 1 item then add 3 other items \newline let s2 = arr.splice(0, 1, "text1", "text2", "text3");} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Data format: Json}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Cặp key-value \newline % Row Count 1 (+ 1) - Key là string \newline % Row Count 2 (+ 1) - Value có thể là array, object, string, number, boolean hoặc null \newline % Row Count 4 (+ 2) Không có dấu phảy cho item cuối cùng% Row Count 5 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Example}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\{ \newline "id": 1, \newline "name": \{ \newline "first\_name": "Vernon", \newline "last\_name": "Harper" \newline \}, \newline "email": "test@gmail.com", \newline "is\_admin": true, \newline "courses": {[}"Accounting", "Statistics"{]}, \newline "other\_info": null \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{JSON object}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{To convert Json \textless{}-{}-\textgreater{} String} \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{JSON.parse(text) -{}-{}-\textgreater{} json \newline JSON.stringify(json) -{}-{}-\textgreater{} string} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Variables}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Global}}: cho toàn app postman} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Collection}}: cho những request nằm trong collection} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Environment}}: cho những request nào sử dụng, không quan tâm collection} \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Data}}: khi đọc file data (csv hoặc json), chỉ có khi sử dụng Runner hoặc Newman} \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Local}}: Khi sử dụng postman script} \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Thứ tự ưu tiên sẽ là: \newline Local (mạnh nhất ) -\textgreater{} data -\textgreater{} environment - \textgreater{} collection -\textgreater{} global (yếu nhất) \newline Note: \newline - object và array: trước khi set thành variable, cần phải {\bf{stringify}} trước \newline - object và array: sau khi get từ variable, cần phải {\bf{parse}} thì mới sử dụng được.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Variable examples}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\seqsplit{pm.globals.set('myVariable'}, MY\_VALUE); \newline pm.globals.get('myVariable'); \newline pm.globals.unset('myVariable'); \newline pm.globals.clear(); \newline \newline pm.collectionVariables.set('myVariable', MY\_VALUE); \newline pm.collectionVariables.get('myVariable'); \newline pm.collectionVariables.unset('myVariable'); \newline pm.collectionVariables.clear(); \newline \newline pm.environment.set('myVariable', MY\_VALUE); \newline pm.environment.get('myVariable'); \newline pm.environment.unset('myVariable'); \newline pm.environment.clear(); \newline pm.environment.name //show name of environment \newline \newline pm.variables.set('myVariable', MY\_VALUE); \newline pm.variables.get('myVariable'); \newline pm.variables.unset('myVariable'); \newline pm.variables.clear(); \newline \newline pm.iterationData.get('myVariable'); \newline \newline pm.variables.replaceIn("myVariable");} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Useful methods}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{// Get (n) random items from an array \newline \_.sample(array, {[}n{]}) \newline \newline let courses\_arr = {[}"programming", "math", "economics", "statistic"{]}; \newline let courses = \_.sample(courses\_arr, 2); // {[}"math", "economics"{]} \newline \newline //Get random number in a range start -\textgreater{} end \newline \_.random(0, 200) //120 \newline \newline // Duplicate (n) times: \newline let a = \_.times(3, \_.random(0, 10)); //{[} 6, 7, 2 {]} \newline \newline \newline //Make random string: \newline Math.random().toString(36).substring(2) //3f4n66lsrq7} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}