
<!doctype html>
<html lang="en" class="no-js">
  <head>
     
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width,initial-scale=1">
      
      
      
        <link rel="canonical" href="http://hexmos.com/lama2/tutorials/examples.html">
      
      <link rel="icon" href="../favicon.ico">
      <meta name="generator" content="mkdocs-1.4.2, mkdocs-material-8.5.10">
    

<meta
  name="description"
  content="Hexmos Lama2: Plain-Text Powered REST API Client for Teams"
/>
<meta
  name="keywords"
  content="api, language, http, dsl, api-client, api-rest, api-design, postman-collection, insomnia"
/>

<!-- Facebook Meta Tags -->
<meta property="og:url" content="https://hexmos.com/lama2" />
<meta property="og:type" content="website" />
<meta
  property="og:title"
  content="Hexmos Lama2: Plain-Text Powered REST API Client for Teams"
/>
<meta
  property="og:description"
  content="Hexmos Lama2: Human-friendly syntax and CLI for describing and executing APIs, store and collaborate on API files using version control. Ships with IDE and text-editor integrations. Markdown for APIs."
/>
<meta property="og:image" content="https://hexmos.com/lama2/banner.png" />

<!-- Twitter Meta Tags -->
<meta name="twitter:card" content="summary_large_image" />
<meta property="twitter:domain" content="hexmos.com" />
<meta property="twitter:url" content="https://hexmos.com/lama2" />
<meta
  name="twitter:title"
  content="Hexmos Lama2: Plain-Text Powered REST API Client for Teams"
/>
<meta
  name="twitter:description"
  content="Hexmos Lama2: Human-friendly syntax and CLI for describing and executing APIs, store and collaborate on API files using version control. Ships with IDE and text-editor integrations. Markdown for APIs."
/>
<meta name="twitter:image" content="https://hexmos.com/lama2/banner.png" />
<script src="../analytics.js"></script>


    
      
        <title>Examples - Hexmos Lama2</title>
      
    
    
      <link rel="stylesheet" href="../assets/stylesheets/main.975780f9.min.css">
      
        
        <link rel="stylesheet" href="../assets/stylesheets/palette.2505c338.min.css">
        
      
      

    
    
    
      
        
        
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
        <style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
      
    
    
    <script>__md_scope=new URL("..",location),__md_hash=e=>[...e].reduce((e,_)=>(e<<5)-e+_.charCodeAt(0),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
    
      
  


  
  


  <script id="__analytics">function __md_analytics(){function n(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],n("js",new Date),n("config","G-WXSDF484XZ"),document.addEventListener("DOMContentLoaded",function(){document.forms.search&&document.forms.search.query.addEventListener("blur",function(){this.value&&n("event","search",{search_term:this.value})}),document$.subscribe(function(){var a=document.forms.feedback;if(void 0!==a)for(var e of a.querySelectorAll("[type=submit]"))e.addEventListener("click",function(e){e.preventDefault();var t=document.location.pathname,e=this.getAttribute("data-md-value");n("event","feedback",{page:t,data:e}),a.firstElementChild.disabled=!0;e=a.querySelector(".md-feedback__note [data-md-value='"+e+"']");e&&(e.hidden=!1)}),a.hidden=!1}),location$.subscribe(function(e){n("config","G-WXSDF484XZ",{page_path:e.pathname})})});var e=document.createElement("script");e.async=!0,e.src="https://www.googletagmanager.com/gtag/js?id=G-WXSDF484XZ",document.getElementById("__analytics").insertAdjacentElement("afterEnd",e)}</script>

  
    <script>"undefined"!=typeof __md_analytics&&__md_analytics()</script>
  

    
    
    
  </head>
  
  
    
    
      
    
    
    
    
    <body dir="ltr" data-md-color-scheme="default" data-md-color-primary="" data-md-color-accent="">
  
    
    
      <script>var palette=__md_get("__palette");if(palette&&"object"==typeof palette.color)for(var key of Object.keys(palette.color))document.body.setAttribute("data-md-color-"+key,palette.color[key])</script>
    
    <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
    <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
    <label class="md-overlay" for="__drawer"></label>
    <div data-md-component="skip">
      
        
        <a href="#examples" class="md-skip">
          Skip to content
        </a>
      
    </div>
    <div data-md-component="announce">
      
    </div>
    
    
      

<header class="md-header" data-md-component="header">
  <nav class="md-header__inner md-grid" aria-label="Header">
    <a href="../index.html" title="Hexmos Lama2" class="md-header__button md-logo" aria-label="Hexmos Lama2" data-md-component="logo">
      
  <img src="../logo.png" alt="logo">

    </a>
    <label class="md-header__button md-icon" for="__drawer">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2Z"/></svg>
    </label>
    <div class="md-header__title" data-md-component="header-title">
      <div class="md-header__ellipsis">
        <div class="md-header__topic">
          <span class="md-ellipsis">
            Hexmos Lama2
          </span>
        </div>
        <div class="md-header__topic" data-md-component="header-topic">
          <span class="md-ellipsis">
            
              Examples
            
          </span>
        </div>
      </div>
    </div>
    
      <form class="md-header__option" data-md-component="palette">
        
          
          
          
          <input class="md-option" data-md-color-media="" data-md-color-scheme="default" data-md-color-primary="" data-md-color-accent=""  aria-label="Switch to dark mode"  type="radio" name="__palette" id="__palette_1">
          
            <label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_2" hidden>
              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a4 4 0 0 0-4 4 4 4 0 0 0 4 4 4 4 0 0 0 4-4 4 4 0 0 0-4-4m0 10a6 6 0 0 1-6-6 6 6 0 0 1 6-6 6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12 20 8.69Z"/></svg>
            </label>
          
        
          
          
          
          <input class="md-option" data-md-color-media="" data-md-color-scheme="slate" data-md-color-primary="" data-md-color-accent=""  aria-label="Switch to light mode"  type="radio" name="__palette" id="__palette_2">
          
            <label class="md-header__button md-icon" title="Switch to light mode" for="__palette_1" hidden>
              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 18c-.89 0-1.74-.2-2.5-.55C11.56 16.5 13 14.42 13 12c0-2.42-1.44-4.5-3.5-5.45C10.26 6.2 11.11 6 12 6a6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12 20 8.69Z"/></svg>
            </label>
          
        
      </form>
    
    
    
      <label class="md-header__button md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
      </label>
      <div class="md-search" data-md-component="search" role="dialog">
  <label class="md-search__overlay" for="__search"></label>
  <div class="md-search__inner" role="search">
    <form class="md-search__form" name="search">
      <input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
      <label class="md-search__icon md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
      </label>
      <nav class="md-search__options" aria-label="Search">
        
        <button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41Z"/></svg>
        </button>
      </nav>
      
    </form>
    <div class="md-search__output">
      <div class="md-search__scrollwrap" data-md-scrollfix>
        <div class="md-search-result" data-md-component="search-result">
          <div class="md-search-result__meta">
            Initializing search
          </div>
          <ol class="md-search-result__list"></ol>
        </div>
      </div>
    </div>
  </div>
</div>
    
    
      <div class="md-header__source">
        <a href="https://github.com/HexmosTech/Lama2" title="Go to repository" class="md-source" data-md-component="source">
  <div class="md-source__icon md-icon">
    
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.2.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81z"/></svg>
  </div>
  <div class="md-source__repository">
    GitHub
  </div>
</a>
      </div>
    
  </nav>
  
</header>
    
    <div class="md-container" data-md-component="container">
      
      
        
          
        
      
      <main class="md-main" data-md-component="main">
        <div class="md-main__inner md-grid">
          
            
              
              <div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    


<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
  <label class="md-nav__title" for="__drawer">
    <a href="../index.html" title="Hexmos Lama2" class="md-nav__button md-logo" aria-label="Hexmos Lama2" data-md-component="logo">
      
  <img src="../logo.png" alt="logo">

    </a>
    Hexmos Lama2
  </label>
  
    <div class="md-nav__source">
      <a href="https://github.com/HexmosTech/Lama2" title="Go to repository" class="md-source" data-md-component="source">
  <div class="md-source__icon md-icon">
    
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.2.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81z"/></svg>
  </div>
  <div class="md-source__repository">
    GitHub
  </div>
</a>
    </div>
  
  <ul class="md-nav__list" data-md-scrollfix>
    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href="../index.html" class="md-nav__link">
        Home
      </a>
    </li>
  

    
      
      
      

  
  
    
  
  
    
      
    
    <li class="md-nav__item md-nav__item--active md-nav__item--section md-nav__item--nested">
      
      
        <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_2" type="checkbox" id="__nav_2" checked>
      
      
      
      
        <label class="md-nav__link" for="__nav_2">
          Get Started
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" aria-label="Get Started" data-md-level="1">
        <label class="md-nav__title" for="__nav_2">
          <span class="md-nav__icon md-icon"></span>
          Get Started
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="installation.html" class="md-nav__link">
        Installation
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="postman.html" class="md-nav__link">
        Import Postman
      </a>
    </li>
  

            
          
            
              
  
  
    
  
  
    <li class="md-nav__item md-nav__item--active">
      
      <input class="md-nav__toggle md-toggle" data-md-toggle="toc" type="checkbox" id="__toc">
      
      
        
      
      
        <label class="md-nav__link md-nav__link--active" for="__toc">
          Examples
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <a href="examples.html" class="md-nav__link md-nav__link--active">
        Examples
      </a>
      
        

<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
  
  
  
    
  
  
    <label class="md-nav__title" for="__toc">
      <span class="md-nav__icon md-icon"></span>
      Table of contents
    </label>
    <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
      
        <li class="md-nav__item">
  <a href="#get-request" class="md-nav__link">
    GET request
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#json-post-request" class="md-nav__link">
    JSON POST request
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#json-post-in-varjson-format" class="md-nav__link">
    JSON POST in VarJSON format
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#comments" class="md-nav__link">
    Comments
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#environment-variables-switch-base-url" class="md-nav__link">
    Environment Variables: Switch base URL
  </a>
  
    <nav class="md-nav" aria-label="Environment Variables: Switch base URL">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#case-1-l2env-adjacent-to-an-api-file" class="md-nav__link">
    Case 1: l2.env adjacent to an API file
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#case-2-root-variables" class="md-nav__link">
    Case 2: Root variables
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#case-3-override-root-variable-with-local-variable" class="md-nav__link">
    Case 3: Override Root variable with local variable
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#headers" class="md-nav__link">
    Headers
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#send-cookies-in-header" class="md-nav__link">
    Send cookies in header
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#fill-forms-attach-files-with-multipart" class="md-nav__link">
    Fill forms &amp; attach files with MULTIPART
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#image-as-base64-encoded-json-field" class="md-nav__link">
    Image as Base64 encoded JSON field
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#chain-requests-using-javascript" class="md-nav__link">
    Chain requests using Javascript
  </a>
  
</li>
      
    </ul>
  
</nav>
      
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="collaboration.html" class="md-nav__link">
        Collaboration
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="codegen.html" class="md-nav__link">
        Code Generation
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="misc.html" class="md-nav__link">
        Misc
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
      
      
      

  
  
  
    
      
    
    <li class="md-nav__item md-nav__item--section md-nav__item--nested">
      
      
        <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_3" type="checkbox" id="__nav_3" >
      
      
      
      
        <label class="md-nav__link" for="__nav_3">
          Understand
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" aria-label="Understand" data-md-level="1">
        <label class="md-nav__title" for="__nav_3">
          <span class="md-nav__icon md-icon"></span>
          Understand
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../explanation/syntax.html" class="md-nav__link">
        Syntax Guidance
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../explanation/l2format.html" class="md-nav__link">
        The l2 Format
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../explanation/faq.html" class="md-nav__link">
        FAQ/RAQ
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
      
      
      

  
  
  
    
      
    
    <li class="md-nav__item md-nav__item--section md-nav__item--nested">
      
      
        <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_4" type="checkbox" id="__nav_4" >
      
      
      
      
        <label class="md-nav__link" for="__nav_4">
          Develop
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" aria-label="Develop" data-md-level="1">
        <label class="md-nav__title" for="__nav_4">
          <span class="md-nav__icon md-icon"></span>
          Develop
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../reference/philosophy.html" class="md-nav__link">
        Design Philosophy
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../reference/architecture.html" class="md-nav__link">
        Architecture
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="editor.html" class="md-nav__link">
        IDE/Editor Support
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../reference/grammar.html" class="md-nav__link">
        Formal Grammar
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../reference/api.html" class="md-nav__link">
        API Reference
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../reference/lsp.html" class="md-nav__link">
        Contribute to LSP
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
      
      
      

  
  
  
    
      
    
    <li class="md-nav__item md-nav__item--section md-nav__item--nested">
      
      
        <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_5" type="checkbox" id="__nav_5" >
      
      
      
      
        <label class="md-nav__link" for="__nav_5">
          LiveAPI
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" aria-label="LiveAPI" data-md-level="1">
        <label class="md-nav__title" for="__nav_5">
          <span class="md-nav__icon md-icon"></span>
          LiveAPI
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../liveapi/aboutliveapi.html" class="md-nav__link">
        About
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../liveapi/setupliveapi.html" class="md-nav__link">
        Easy Installation
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
      
      
      

  
  
  
    
      
    
    <li class="md-nav__item md-nav__item--section md-nav__item--nested">
      
      
        <input class="md-nav__toggle md-toggle" data-md-toggle="__nav_6" type="checkbox" id="__nav_6" >
      
      
      
      
        <label class="md-nav__link" for="__nav_6">
          About
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" aria-label="About" data-md-level="1">
        <label class="md-nav__title" for="__nav_6">
          <span class="md-nav__icon md-icon"></span>
          About
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../about/hexmos.html" class="md-nav__link">
        Hexmos
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../about/contact.html" class="md-nav__link">
        Talk to us
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
  </ul>
</nav>
                  </div>
                </div>
              </div>
            
            
              
              <div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    

<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
  
  
  
    
  
  
    <label class="md-nav__title" for="__toc">
      <span class="md-nav__icon md-icon"></span>
      Table of contents
    </label>
    <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
      
        <li class="md-nav__item">
  <a href="#get-request" class="md-nav__link">
    GET request
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#json-post-request" class="md-nav__link">
    JSON POST request
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#json-post-in-varjson-format" class="md-nav__link">
    JSON POST in VarJSON format
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#comments" class="md-nav__link">
    Comments
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#environment-variables-switch-base-url" class="md-nav__link">
    Environment Variables: Switch base URL
  </a>
  
    <nav class="md-nav" aria-label="Environment Variables: Switch base URL">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#case-1-l2env-adjacent-to-an-api-file" class="md-nav__link">
    Case 1: l2.env adjacent to an API file
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#case-2-root-variables" class="md-nav__link">
    Case 2: Root variables
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#case-3-override-root-variable-with-local-variable" class="md-nav__link">
    Case 3: Override Root variable with local variable
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#headers" class="md-nav__link">
    Headers
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#send-cookies-in-header" class="md-nav__link">
    Send cookies in header
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#fill-forms-attach-files-with-multipart" class="md-nav__link">
    Fill forms &amp; attach files with MULTIPART
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#image-as-base64-encoded-json-field" class="md-nav__link">
    Image as Base64 encoded JSON field
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#chain-requests-using-javascript" class="md-nav__link">
    Chain requests using Javascript
  </a>
  
</li>
      
    </ul>
  
</nav>
                  </div>
                </div>
              </div>
            
          
          
            <div class="md-content" data-md-component="content">
              <article class="md-content__inner md-typeset">
                
                  

  <a href="https://github.com/HexmosTech/Lama2/edit/master/docs/tutorials/examples.md" title="Edit this page" class="md-content__button md-icon">
    
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20.71 7.04c.39-.39.39-1.04 0-1.41l-2.34-2.34c-.37-.39-1.02-.39-1.41 0l-1.84 1.83 3.75 3.75M3 17.25V21h3.75L17.81 9.93l-3.75-3.75L3 17.25Z"/></svg>
  </a>


<h1 id="examples">Examples<a class="headerlink" href="#examples" title="Permanent link">&para;</a></h1>
<p>The following examples provide a sampling of
the various types of requests <em>Lama2</em> handles
presently. Execute each file as:</p>
<div class="highlight"><pre><span></span><code>l2 &lt;file_name&gt;.l2
</code></pre></div>
<p>You can also clone the repo and open it up in
VSCode, install the <em>Lama2</em> extension and fire
requests from there.</p>
<h2 id="get-request">GET request<a class="headerlink" href="#get-request" title="Permanent link">&para;</a></h2>
<pre id="liveapi-element">
GET
https://httpbin.org/get

---

_METADATA = {"sample_response":{
  "args": {},
  "headers": {
    "Accept": "*/*",
    "Accept-Encoding": "gzip, deflate",
    "Host": "httpbin.org",
    "User-Agent": "python-requests/2.25.1",
    "X-Amzn-Trace-Id": "Root=1-6686c611-62649d393aae96de5f4afcbf"
  },
  "origin": "20.235.244.147",
  "url": "https://httpbin.org/get"
},
"api_name":"GET Request",
"api_url":"https://httpbin.org/ip",
"api_description": "Does a request to get the IP Address"
}
</pre>

<p>Get <a href="https://github.com/HexmosTech/Lama2/tree/main/examples/0000_sample_get.l2">Source File</a></p>
<h2 id="json-post-request">JSON POST request<a class="headerlink" href="#json-post-request" title="Permanent link">&para;</a></h2>
<p>One can dump the JSON body at the end of an <code>.l2</code> file to create a POST request:</p>
<pre id="liveapi-element">
POST
https://httpbin.org/post

{
    "a": "b",
    "c": "d"
}

---

_METADATA={
    "sample_response":{
  "args": {},
  "data": "{\"a\":\"b\",\"c\":\"d\"}",
  "files": {},
  "form": {},
  "headers": {
    "Accept": "*/*",
    "Accept-Encoding": "gzip, deflate",
    "Content-Length": "17",
    "Content-Type": "application/json",
    "Host": "httpbin.org",
    "User-Agent": "python-requests/2.25.1",
    "X-Amzn-Trace-Id": "Root=1-6686c6c4-43e22f6539f1dae9070b962b"
  },
  "json": {
    "a": "b",
    "c": "d"
  },
  "origin": "20.235.244.147",
  "url": "https://httpbin.org/post"
},
    "api_name" : "POST Request"
}
</pre>

<p>Get <a href="https://github.com/HexmosTech/Lama2/tree/main/examples/0002_sample_post.l2">Source File</a></p>
<h2 id="json-post-in-varjson-format">JSON POST in VarJSON format<a class="headerlink" href="#json-post-in-varjson-format" title="Permanent link">&para;</a></h2>
<p>Make a POST request with JSON body specified
as <code>key=value</code>. <em>Lama2</em> converts the input into
a corresponding JSON value <code>{"a": "b", "c": "d"}</code>. We call the <code>key=value</code> format <em>VarJSON</em>. This example produces an effect identical to the <a href="#basic-json-post">previous one</a></p>
<pre id="liveapi-element">
POST
https://httpbin.org/post

a=b
c=d
---
_METADATA={
    "api_name":"POST Request in VarJSON",
    "sample_response":{
        "args": {},
        "data": "{\"a\":\"b\",\"c\":\"d\"}",
        "files": {},
        "form": {},
        "headers": {
            "Accept": "*/*",
            "Accept-Encoding": "gzip, deflate",
            "Content-Length": "17",
            "Content-Type": "application/json",
            "Host": "httpbin.org",
            "User-Agent": "python-requests/2.25.1",
            "X-Amzn-Trace-Id": "Root=1-6686c721-0e9da41a16bc944d5fabe460"
        },
        "json": {
            "a": "b",
            "c": "d"
        },
        "origin": "20.235.244.147",
        "url": "https://httpbin.org/post"
    }
}
</pre>

<p>Get <a href="https://github.com/HexmosTech/Lama2/tree/main/examples/0001_sample_post_varjson.l2">Source File</a></p>
<h2 id="comments">Comments<a class="headerlink" href="#comments" title="Permanent link">&para;</a></h2>
<p>One can start a comment anywhere in the file
with the <code>#</code> character.</p>
<pre id="liveapi-element">
# Pound symbol signifies a comment
POST
https://httpbin.org/post

a=b # Comments may start at the end of lines as well
c=d

# Comments work even after the payload

---

_METADATA={
    "api_name":"Request with comments",
    "sample_response":{
  "args": {},
  "data": "{\"a\":\"b\",\"c\":\"d\"}",
  "files": {},
  "form": {},
  "headers": {
    "Accept": "*/*",
    "Accept-Encoding": "gzip, deflate",
    "Content-Length": "17",
    "Content-Type": "application/json",
    "Host": "httpbin.org",
    "User-Agent": "python-requests/2.25.1",
    "X-Amzn-Trace-Id": "Root=1-6686c73a-1c05768a182e50a86b161667"
  },
  "json": {
    "a": "b",
    "c": "d"
  },
  "origin": "20.235.244.147",
  "url": "https://httpbin.org/post"
}
}
</pre>

<p>Get <a href="https://github.com/HexmosTech/Lama2/tree/main/examples/0003_comment.l2">Source File</a></p>
<h2 id="environment-variables-switch-base-url">Environment Variables: Switch base URL<a class="headerlink" href="#environment-variables-switch-base-url" title="Permanent link">&para;</a></h2>
<h3 id="case-1-l2env-adjacent-to-an-api-file">Case 1: <code>l2.env</code> adjacent to an API file<a class="headerlink" href="#case-1-l2env-adjacent-to-an-api-file" title="Permanent link">&para;</a></h3>
<p>For any given <code>.l2</code> file, one can place an <code>l2.env</code> file to store relevant variables.
These variables will be available to be used within the API file</p>
<p><strong>project_folder/api/l2.env</strong></p>
<div class="highlight"><pre><span></span><code>export AHOST=&quot;http://127.0.0.1:8000&quot;
</code></pre></div>
<p><strong>project_folder/api/get_users.l2</strong></p>
<pre id="liveapi-element">
GET
${AHOST}/users

---

_METADATA={
    "api_name": "Environment Variables"
}
</pre>

<p><img alt="l2.env at API level" src="l2env.png" /></p>
<p>Get <a href="https://github.com/HexmosTech/Lama2/tree/main/examples/0023_l2env_declare">Source File</a></p>
<h3 id="case-2-root-variables">Case 2: Root variables<a class="headerlink" href="#case-2-root-variables" title="Permanent link">&para;</a></h3>
<p>In Lama2, you can have a large number of API files stored in a hierarchical folder configuration.
The root of such a project can be signified through <code>l2config.env</code>:</p>
<p>Within such a structure, you can have an API file anywhere, which can use variables defined in the root variables:</p>
<p><strong>project_folder/l2config.env</strong></p>
<div class="highlight"><pre><span></span><code>export AHOST=&quot;https://httpbin.org&quot;
export BHOST=&quot;https://google.com&quot;
</code></pre></div>
<p><strong>project_folder/api/get_users.l2</strong></p>
<pre id="liveapi-element">
GET
${AHOST}/users

---

_METADATA={
    "api_name": "Environment Variables"
}

</pre>

<p><img alt="l2config.env at Project root level" src="l2configAtRoot.png" /></p>
<p>Get <a href="https://github.com/HexmosTech/Lama2/tree/main/examples/0022_l2config_declare">Source File</a></p>
<h3 id="case-3-override-root-variable-with-local-variable">Case 3: Override Root variable with local variable<a class="headerlink" href="#case-3-override-root-variable-with-local-variable" title="Permanent link">&para;</a></h3>
<p>In this structure, if a variable is declared in both l2config.env and l2.env, the value from l2.env takes precedence.</p>
<p><strong>project_folder/l2config.env</strong></p>
<div class="highlight"><pre><span></span><code>export AHOST=`echo NO URL`
export BHOST=&quot;https://httpbin.org&quot;
</code></pre></div>
<p><strong>project_folder/api/l2.env</strong></p>
<div class="highlight"><pre><span></span><code>export AHOST=&quot;http://127.0.0.1:8000&quot;
</code></pre></div>
<p><strong>project_folder/api/get_users.l2</strong></p>
<pre id="liveapi-element">
GET
${AHOST}/users

---

_METADATA={
    "api_name": "Environment Variables"
}

</pre>

<p><img alt="Override of l2config.env with l2.env variable" src="l2envOverideL2config.png" /></p>
<p><img alt="l2envvariable variable" src="l2envvariable.png" /></p>
<p><img alt="l2configvariable variable" src="l2configvariable.png" /></p>
<p>Get <a href="https://github.com/HexmosTech/Lama2/tree/main/examples/0020_override_project_root_local">Source File</a></p>
<h2 id="headers">Headers<a class="headerlink" href="#headers" title="Permanent link">&para;</a></h2>
<p>Use <code>key:value</code> format to specify headers.</p>
<p>Specify strings for key/value in three ways:</p>
<ol>
<li>Double quoted (<code>"hello"</code>)</li>
<li>Single quoted (<code>'hello'</code>)</li>
<li>Unquoted (<code>hello</code>)</li>
</ol>
<pre id="liveapi-element">
POST
https://httpbin.org/post

# HEADERS
X-Parse-Application-Id:'helloworld'
X-Parse-REST-API-Key:"byeworld"

# DATA
a="b"  # double-quoted string
'c'=d  # single-quoted & unquoted strings

---

_METADATA={
    "api_name":"Header Example 1",
    "sample_response":{
  "args": {},
  "data": "{\"a\":\"b\",\"c\":\"d\"}",
  "files": {},
  "form": {},
  "headers": {
    "Accept": "*/*",
    "Accept-Encoding": "gzip, deflate",
    "Content-Length": "17",
    "Content-Type": "application/json",
    "Host": "httpbin.org",
    "User-Agent": "python-requests/2.25.1",
    "X-Amzn-Trace-Id": "Root=1-6686c782-2fd42fdd70a089580fe2c166"
  },
  "json": {
    "a": "b",
    "c": "d"
  },
  "origin": "20.235.244.147",
  "url": "https://httpbin.org/post"
}
}
</pre>

<p>Get <a href="https://github.com/HexmosTech/Lama2/tree/main/examples/0005_headers_simple.l2">Source File</a></p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The data section may appear <em>before</em> headers as well (see below)</p>
</div>
<pre id="liveapi-element">
POST
https://httpbin.org/post


# DATA
a="b"  # double-quoted string
'c'=d  # single-quoted & unquoted strings

# HEADERS
X-Parse-Application-Id:'helloworld'
X-Parse-REST-API-Key:"byeworld"

---

_METADATA={
    "api_name":"Header Example 2",
    "sample_response":{
  "args": {},
  "data": "{\"a\":\"b\",\"c\":\"d\"}",
  "files": {},
  "form": {},
  "headers": {
    "Accept": "*/*",
    "Accept-Encoding": "gzip, deflate",
    "Content-Length": "17",
    "Content-Type": "application/json",
    "Host": "httpbin.org",
    "User-Agent": "python-requests/2.25.1",
    "X-Amzn-Trace-Id": "Root=1-6686c7f1-7bfd09a2000d33bc12cbf7c1"
  },
  "json": {
    "a": "b",
    "c": "d"
  },
  "origin": "20.235.244.147",
  "url": "https://httpbin.org/post"
},
  "json": {
    "a": "b",
    "c": "d"
  },
  "origin": "20.235.244.147",
  "url": "https://httpbin.org/post"
}

</pre>

<h2 id="send-cookies-in-header">Send cookies in header<a class="headerlink" href="#send-cookies-in-header" title="Permanent link">&para;</a></h2>
<p>Headers represent cookies in <em>Lama2</em>. Just specify cookie key value pairs separated by
<code>=</code> within the header value as shown.</p>
<pre id="liveapi-element">
POST
https://httpbin.org/post

# HEADERS
Cookie:"sessionid=foo;another-cookie=bar"

# DATA
hello=world

---

_METADATA={
    "api_name":"Cookie Request",
    "sample_response" : {
  "args": {},
  "data": "{\"hello\":\"world\"}",
  "files": {},
  "form": {},
  "headers": {
    "Accept": "*/*",
    "Accept-Encoding": "gzip, deflate",
    "Content-Length": "17",
    "Content-Type": "application/json",
    "Host": "httpbin.org",
    "User-Agent": "python-requests/2.25.1",
    "X-Amzn-Trace-Id": "Root=1-6686c850-33bc68696295ac947eb27420"
  },
  "json": {
    "hello": "world"
  },
  "origin": "20.235.244.147",
  "url": "https://httpbin.org/post"
}
}
</pre>

<p>Get <a href="https://github.com/HexmosTech/Lama2/tree/main/examples/0006_cookies.l2">Source File</a></p>
<h2 id="fill-forms-attach-files-with-multipart">Fill forms &amp; attach files with MULTIPART<a class="headerlink" href="#fill-forms-attach-files-with-multipart" title="Permanent link">&para;</a></h2>
<p>Use the <code>MULTIPART</code> keyword after the HTTP
verb to enable forms and file attachments.</p>
<p>The data section may contain any number of
form inputs using the <code>key=value</code> syntax.</p>
<p>Following the data section, one can specify
any number of files in the form of <code>&lt;field_name&gt;@&lt;file_path&gt;</code>. The file path is
relative to the API file.</p>
<pre id="liveapi-element">
POST
MULTIPART
http://httpbin.org/post

'X-Parse-Application-Id':hello
X-Parse-REST-API-Key:"world"

# DATA
first=second

# FILES
myfile@./image.jpeg

---

_METADATA={
    "api_name" : "Multipart Request"
}
</pre>

<p>Get <a href="https://github.com/HexmosTech/Lama2/tree/main/examples/0007_multipart_file">Source Files</a></p>
<h2 id="image-as-base64-encoded-json-field">Image as Base64 encoded JSON field<a class="headerlink" href="#image-as-base64-encoded-json-field" title="Permanent link">&para;</a></h2>
<p>We can embed images (or other files) as
base64 strings in JSON using <em>Lama2</em>.</p>
<p>First, we define a <code>PHOTO</code> variable, loaded
up with the results of the <code>base64</code> command.</p>
<p><strong>l2.env</strong></p>
<div class="highlight"><pre><span></span><code>export PHOTO=`base64 -w 0 image.jpeg`
</code></pre></div>
<p>Next, we refer to the <code>PHOTO</code> variable in
the API file. Pay special attention to the
quoting mechanism <code>"'{PHOTO}'"</code>.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p><strong>The quoting
must look exactly as shown in the following
template for the request to work correctly.</strong></p>
</div>
<p><strong>base64_embed.l2</strong></p>
<pre id="liveapi-element">
POST
http://httpbin.org/post

{
    "imageb64_field": "'${PHOTO}'",
}

---

_METADATA={
    "api_name" : "Image Example 2"
}
</pre>

<p>Get <a href="https://github.com/HexmosTech/Lama2/tree/main/examples/0008_base64_image">Source Files</a></p>
<h2 id="chain-requests-using-javascript">Chain requests using Javascript<a class="headerlink" href="#chain-requests-using-javascript" title="Permanent link">&para;</a></h2>
<p>In Lama2, we have alternating requestor and processor (JS) blocks, separated by <code>---</code>.</p>
<p>Each processor (JS) block has a special variable <code>result</code>, storing the response
from previous requestor block. If possible,
<code>result</code> is automatically stored as a JS
object through <code>JSON.parse()</code>. Otherwise,
<code>result</code> is stored as a regular <code>string</code>.</p>
<pre id="liveapi-element">
url = "http://google.com"
REMOTE_COORD = "https://httpbin.org"
---
# stage 1

POST
${REMOTE_COORD}/anything

{
    "username": "admin",
    "password": "Password@123",
    "from": "${LOCAL_COORD}/anything",
    "url": "${url}",
    "Token": "MySuperSecretToken"
}

---

// filtering, store in var
console.log("@@Result", result)
TOKEN = result["json"]["Token"]
console.log(TOKEN)

---

# stage 2
GET
${REMOTE_COORD}/bearer

Authorization: 'Bearer ${TOKEN}'

---

_METADATA={
    "api_name" : "Chain Request"
}

</pre>

<p>Get <a href="https://github.com/HexmosTech/Lama2/tree/main/examples/0009_processor_basic">Source Files</a></p>


  




                
              </article>
            </div>
          
          
        </div>
        
          <a href="#" class="md-top md-icon" data-md-component="top" hidden>
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8v12Z"/></svg>
            Back to top
          </a>
        
      </main>
       
        <footer class="md-footer">
  
    
    <nav class="md-footer__inner md-grid" aria-label="Footer" >
      
        
        <a href="postman.html" class="md-footer__link md-footer__link--prev" aria-label="Previous: Import Postman" rel="prev">
          <div class="md-footer__button md-icon">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
          </div>
          <div class="md-footer__title">
            <div class="md-ellipsis">
              <span class="md-footer__direction">
                Previous
              </span>
              Import Postman
            </div>
          </div>
        </a>
      
      
        
        <a href="collaboration.html" class="md-footer__link md-footer__link--next" aria-label="Next: Collaboration" rel="next">
          <div class="md-footer__title">
            <div class="md-ellipsis">
              <span class="md-footer__direction">
                Next
              </span>
              Collaboration
            </div>
          </div>
          <div class="md-footer__button md-icon">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 11v2h12l-5.5 5.5 1.42 1.42L19.84 12l-7.92-7.92L10.5 5.5 16 11H4Z"/></svg>
          </div>
        </a>
      
    </nav>
  
  <div class="md-footer-meta md-typeset">
    <div class="md-footer-meta__inner md-grid">
      <div class="md-copyright">
  
  
    Made with
    <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
      Material for MkDocs
    </a>
  
</div>
      
    </div>
  </div>
</footer>
      

<script>
  ((w, d, s) => {
    w.liveAPI = (...args) => (w.liveAPI.q = w.liveAPI.q || []).push(args);
    d.head.appendChild(Object.assign(d.createElement("script"), { src: s, async: true }));
  })(window, document, `https://d2q4vn0gqet98u.cloudfront.net/latest/liveapi.js?foo=${Math.random().toString(36).slice(2)}`);
  liveAPI("loadwidget", {
    selectors: ['#liveapi-element'],
  });
</script>


    </div>
    <div class="md-dialog" data-md-component="dialog">
      <div class="md-dialog__inner md-typeset"></div>
    </div>
    
    <script id="__config" type="application/json">{"base": "..", "features": ["navigation.tracking", "navigation.sections", "toc.follow", "navigation.top"], "search": "../assets/javascripts/workers/search.16e2a7d4.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.config.lang": "en", "search.config.pipeline": "trimmer, stopWordFilter", "search.config.separator": "[\\s\\-]+", "search.placeholder": "Search", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version.title": "Select version"}}</script>
    
    
      <script src="../assets/javascripts/bundle.5a2dcb6a.min.js"></script>
      
        <script src="../links.js"></script>
      
    
    
  </body>
</html>