Skip to content

Commit

Permalink
Updating l2format and examples, documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lovestaco committed Jul 22, 2023
1 parent 94dcf64 commit 16e5a00
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 59 deletions.
39 changes: 20 additions & 19 deletions docs/Lama2/docs/explanation/l2format.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ Cookies are specified in a `Cookie` header as follows:
Cookie:'sessionid=foo;another-cookie=bar'
```


### Environment Variables: Switch base URL

#### API variables can be defined in `apirequest.l2`

L2 uses the variables declared inside the `.l2` file and makes the request
Variables are declared within the JS processor block and serve as dynamic placeholders for data used in API requests.
By utilizing these variables, L2 enables flexibility and reusability in defining API endpoints and data payloads.

Example `login.l2`:

Expand All @@ -106,42 +107,41 @@ Get [Source Files](https://github.com/HexmosTech/Lama2/tree/main/examples/0021_v


#### API environment variables can be defined locally in `l2.env`
L2 provides a convenient way to define environment variables through the l2.env file.
This file is automatically searched for in the present directory,
and its contents are loaded to create a set of variables(local).

`l2.env` is searched for, from the present directory and variables(local) are loaded from this file.

Example `l2.env`:

```
export PHOTO=`base64 aadhaarlarge.jpg`
export AHOST="http://localhost:8000"
```
In the `l2.env` file, you can specify environment-specific values for variables used in your L2 scripts, such as URLs, authentication tokens, or any other data that may vary depending on the environment in which the API requests are executed.

![l2.env at API level](l2env.png)

Go to [Example](https://hexmos.com/lama2/tutorials/examples.html#case-1-l2env-adjacent-to-an-api-file)

Get [Source File](https://github.com/HexmosTech/Lama2/tree/main/examples/0023_l2env_declare)


#### API environment variables can be defined at project root using `l2config.env`
`l2config.env` is searched for, from the present directory to all its ancestors (upto `/`) and
variables(root) are loaded from this file.
Example `l2config.env`:
The `l2config.env` file serves as a centralized storage for environment variables located at the project root, streamlining the management of configuration settings across all L2 scripts. With this file present, every L2 script within the project automatically inherits the defined variables, effectively eliminating the necessity to duplicate configurations in individual subdirectories using `l2.env`.

```
export PHOTO=`base64 aadhaarsmall.jpg`
export AHOST="http://localhost:8001"
```
The search for `l2config.env` extends from the present directory up to the root directory (`/`). During this process, the variables defined in the root file are loaded and made available for use in all relevant scripts. This approach significantly enhances efficiency and maintainability, as it ensures consistent settings throughout the project while reducing redundancy in configuration data.

![l2config.env at Project root level](l2configAtRoot.png)

Go to [Example](https://hexmos.com/lama2/tutorials/examples.html#case-2-root-variables)

Get [Source File](https://github.com/HexmosTech/Lama2/tree/main/examples/0022_l2config_declare)

#### If `l2config.env`(root) variables are redeclared in `l2.env`(local)

The local variable's value is taken into consideration regardless of both files residing in same directory
#### If `l2config.env`(root) variables are redeclared in `l2.env`(local)
In situations where both root and local variables share the same variable name, the local variable takes precedence over the root variable. This behavior remains consistent, even if both `l2config.env` (root) and `l2.env` (local) files reside in the same directory. The local variable's value will always be considered over the root variable, ensuring that specific configurations defined at the local level effectively override any corresponding settings present in the root file. This approach provides developers with granular control and flexibility in tailoring environment variables to suit specific needs within different parts of the project while maintaining the overall structure and organization of configuration settings.

![l2config.env at Project root level](l2envOverideL2config.png)

Go to [Example](https://hexmos.com/lama2/tutorials/examples.html#case-3-override-root-variable-with-local-variable)

Get [Source File](https://github.com/HexmosTech/Lama2/tree/main/examples/0020_override_project_root_local)


### The environment file can load results of commands

Use the backtick notation `\`command\`` to place the results of
Expand All @@ -153,6 +153,7 @@ export PHOTO=`base64 image.jpeg`

One can load the `PHOTO` variable in API files.


### Chain requests through Javascript blocks

*Lama2* supports plain Javascript (JS) blocks
Expand Down
46 changes: 37 additions & 9 deletions docs/Lama2/docs/tutorials/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,44 +71,72 @@ c=d

Get [Source File](https://github.com/HexmosTech/Lama2/tree/main/examples/0003_comment.l2)

## Environment Variables: Switch base URL

## Environment Variables:
### Case 1: `l2.env` adjacent to an API file

For any given `.l2` file, one can place an `l2.env` file to store relevant variables.
These variables will be available to be used within the API file

**l2.env**
**project_folder/api/l2.env**
```
export AHOST="http://127.0.0.1:8000"
```

**project_folder/api/get_users.l2**
```
export LOCAL="http://localhost:8000"
export REMOTE="http://httpbin.org"
GET
${AHOST}/users
```

![l2.env at API level](l2env.png)

Get [Source File](https://github.com/HexmosTech/Lama2/tree/main/examples/0023_l2env_declare)


### Case 2: Root variables

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 `l2config.env`:

Within such a structure, you can have an API file anywhere, which can use variables defined in the root variables:
**l2config.env**

**project_folder/l2config.env**
```
export LOCAL="http://localhost:8000"
export REMOTE="http://httpbin.org"
export AHOST="https://httpbin.org"
export BHOST="https://google.com"
```

**project_folder/api/get_users.l2**
```
GET
${AHOST}/users
```

![l2config.env at Project root level](l2configAtRoot.png)

Get [Source File](https://github.com/HexmosTech/Lama2/tree/main/examples/0022_l2config_declare)

### Case 3: Override Root variable with local variable

### Case 3: Override Root variable with local variable
In this structure, if a variable is declared in both l2config.env and l2.env, the value from l2.env takes precedence.

**project_folder/l2config.env**
```
export AHOST=`echo NO URL`
export BHOST="https://httpbin.org"
```

**project_folder/api/l2.env**
```
export AHOST="http://127.0.0.1:8000"
```

**project_folder/api/get_users.l2**
```
GET
${AHOST}/users
```

![Override of l2config.env with l2.env variable](l2envOverideL2config.png)

Get [Source File](https://github.com/HexmosTech/Lama2/tree/main/examples/0020_override_project_root_local)
Expand Down
25 changes: 12 additions & 13 deletions docs/Lama2/site/explanation/l2format.html
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,8 @@ <h3 id="cookies-are-sent-as-headers">Cookies are sent as headers<a class="header
</code></pre></div>
<h3 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></h3>
<h4 id="api-variables-can-be-defined-in-apirequestl2">API variables can be defined in <code>apirequest.l2</code><a class="headerlink" href="#api-variables-can-be-defined-in-apirequestl2" title="Permanent link">&para;</a></h4>
<p>L2 uses the variables declared inside the <code>.l2</code> file and makes the request</p>
<p>Variables are declared within the JS processor block and serve as dynamic placeholders for data used in API requests.
By utilizing these variables, L2 enables flexibility and reusability in defining API endpoints and data payloads.</p>
<p>Example <code>login.l2</code>:</p>
<div class="highlight"><pre><span></span><code>let REMOTE = &quot;httpbin.org&quot;
let EMAIL = &quot;[email protected]&quot;
Expand All @@ -1013,25 +1014,23 @@ <h4 id="api-variables-can-be-defined-in-apirequestl2">API variables can be defin
</code></pre></div>
<p>Get <a href="https://github.com/HexmosTech/Lama2/tree/main/examples/0021_varjson_variable/0021_varjson_variable.l2">Source Files</a></p>
<h4 id="api-environment-variables-can-be-defined-locally-in-l2env">API environment variables can be defined locally in <code>l2.env</code><a class="headerlink" href="#api-environment-variables-can-be-defined-locally-in-l2env" title="Permanent link">&para;</a></h4>
<p><code>l2.env</code> is searched for, from the present directory and variables(local) are loaded from this file.</p>
<p>Example <code>l2.env</code>:</p>
<div class="highlight"><pre><span></span><code>export PHOTO=`base64 aadhaarlarge.jpg`
export AHOST=&quot;http://localhost:8000&quot;
</code></pre></div>
<p>L2 provides a convenient way to define environment variables through the l2.env file.
This file is automatically searched for in the present directory,
and its contents are loaded to create a set of variables(local).</p>
<p>In the <code>l2.env</code> file, you can specify environment-specific values for variables used in your L2 scripts, such as URLs, authentication tokens, or any other data that may vary depending on the environment in which the API requests are executed.</p>
<p><img alt="l2.env at API level" src="l2env.png" /></p>
<p>Go to <a href="https://hexmos.com/lama2/tutorials/examples.html#case-1-l2env-adjacent-to-an-api-file">Example</a></p>
<p>Get <a href="https://github.com/HexmosTech/Lama2/tree/main/examples/0023_l2env_declare">Source File</a></p>
<h4 id="api-environment-variables-can-be-defined-at-project-root-using-l2configenv">API environment variables can be defined at project root using <code>l2config.env</code><a class="headerlink" href="#api-environment-variables-can-be-defined-at-project-root-using-l2configenv" title="Permanent link">&para;</a></h4>
<p><code>l2config.env</code> is searched for, from the present directory to all its ancestors (upto <code>/</code>) and
variables(root) are loaded from this file.
Example <code>l2config.env</code>:</p>
<div class="highlight"><pre><span></span><code>export PHOTO=`base64 aadhaarsmall.jpg`
export AHOST=&quot;http://localhost:8001&quot;
</code></pre></div>
<p>The <code>l2config.env</code> file serves as a centralized storage for environment variables located at the project root, streamlining the management of configuration settings across all L2 scripts. With this file present, every L2 script within the project automatically inherits the defined variables, effectively eliminating the necessity to duplicate configurations in individual subdirectories using <code>l2.env</code>.</p>
<p>The search for <code>l2config.env</code> extends from the present directory up to the root directory (<code>/</code>). During this process, the variables defined in the root file are loaded and made available for use in all relevant scripts. This approach significantly enhances efficiency and maintainability, as it ensures consistent settings throughout the project while reducing redundancy in configuration data.</p>
<p><img alt="l2config.env at Project root level" src="l2configAtRoot.png" /></p>
<p>Go to <a href="https://hexmos.com/lama2/tutorials/examples.html#case-2-root-variables">Example</a></p>
<p>Get <a href="https://github.com/HexmosTech/Lama2/tree/main/examples/0022_l2config_declare">Source File</a></p>
<h4 id="if-l2configenvroot-variables-are-redeclared-in-l2envlocal">If <code>l2config.env</code>(root) variables are redeclared in <code>l2.env</code>(local)<a class="headerlink" href="#if-l2configenvroot-variables-are-redeclared-in-l2envlocal" title="Permanent link">&para;</a></h4>
<p>The local variable's value is taken into consideration regardless of both files residing in same directory</p>
<p>In situations where both root and local variables share the same variable name, the local variable takes precedence over the root variable. This behavior remains consistent, even if both <code>l2config.env</code> (root) and <code>l2.env</code> (local) files reside in the same directory. The local variable's value will always be considered over the root variable, ensuring that specific configurations defined at the local level effectively override any corresponding settings present in the root file. This approach provides developers with granular control and flexibility in tailoring environment variables to suit specific needs within different parts of the project while maintaining the overall structure and organization of configuration settings.</p>
<p><img alt="l2config.env at Project root level" src="l2envOverideL2config.png" /></p>
<p>Go to <a href="https://hexmos.com/lama2/tutorials/examples.html#case-3-override-root-variable-with-local-variable">Example</a></p>
<p>Get <a href="https://github.com/HexmosTech/Lama2/tree/main/examples/0020_override_project_root_local">Source File</a></p>
<h3 id="the-environment-file-can-load-results-of-commands">The environment file can load results of commands<a class="headerlink" href="#the-environment-file-can-load-results-of-commands" title="Permanent link">&para;</a></h3>
<p>Use the backtick notation <code>\</code>command`` to place the results of
Expand Down
2 changes: 1 addition & 1 deletion docs/Lama2/site/search/search_index.json

Large diffs are not rendered by default.

Binary file modified docs/Lama2/site/sitemap.xml.gz
Binary file not shown.
52 changes: 35 additions & 17 deletions docs/Lama2/site/tutorials/examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,11 @@
</li>

<li class="md-nav__item">
<a href="#environment-variables-switch-base-url" class="md-nav__link">
Environment Variables: Switch base URL
<a href="#environment-variables" class="md-nav__link">
Environment Variables:
</a>

<nav class="md-nav" aria-label="Environment Variables: Switch base URL">
<nav class="md-nav" aria-label="Environment Variables:">
<ul class="md-nav__list">

<li class="md-nav__item">
Expand Down Expand Up @@ -830,11 +830,11 @@
</li>

<li class="md-nav__item">
<a href="#environment-variables-switch-base-url" class="md-nav__link">
Environment Variables: Switch base URL
<a href="#environment-variables" class="md-nav__link">
Environment Variables:
</a>

<nav class="md-nav" aria-label="Environment Variables: Switch base URL">
<nav class="md-nav" aria-label="Environment Variables:">
<ul class="md-nav__list">

<li class="md-nav__item">
Expand Down Expand Up @@ -967,28 +967,46 @@ <h2 id="comments">Comments<a class="headerlink" href="#comments" title="Permanen
# Comments work even after the payload
</code></pre></div>
<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>
<h2 id="environment-variables">Environment Variables:<a class="headerlink" href="#environment-variables" 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>l2.env</strong></p>
<div class="highlight"><pre><span></span><code>export LOCAL=&quot;http://localhost:8000&quot;
export REMOTE=&quot;http://httpbin.org&quot;
</code></pre></div>
<p><strong>project_folder/api/l2.env</strong>
<div class="highlight"><pre><span></span><code>export AHOST=&quot;http://127.0.0.1:8000&quot;
</code></pre></div></p>
<p><strong>project_folder/api/get_users.l2</strong>
<div class="highlight"><pre><span></span><code>GET
${AHOST}/users
</code></pre></div></p>
<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:
<strong>l2config.env</strong></p>
<p><div class="highlight"><pre><span></span><code>export LOCAL=&quot;http://localhost:8000&quot;
export REMOTE=&quot;http://httpbin.org&quot;
</code></pre></div>
<img alt="l2config.env at Project root level" src="l2configAtRoot.png" /></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>
<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>
<p><strong>project_folder/api/get_users.l2</strong>
<div class="highlight"><pre><span></span><code>GET
${AHOST}/users
</code></pre></div></p>
<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>
<div class="highlight"><pre><span></span><code>export AHOST=`echo NO URL`
export BHOST=&quot;https://httpbin.org&quot;
</code></pre></div></p>
<p><strong>project_folder/api/l2.env</strong>
<div class="highlight"><pre><span></span><code>export AHOST=&quot;http://127.0.0.1:8000&quot;
</code></pre></div></p>
<p><strong>project_folder/api/get_users.l2</strong>
<div class="highlight"><pre><span></span><code>GET
${AHOST}/users
</code></pre></div></p>
<p><img alt="Override of l2config.env with l2.env variable" src="l2envOverideL2config.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>
Expand Down

0 comments on commit 16e5a00

Please sign in to comment.