<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by nostop8 on Medium]]></title>
        <description><![CDATA[Stories by nostop8 on Medium]]></description>
        <link>https://medium.com/@nostop8?source=rss-c75cc990c78b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ASbP79m0MmGU0lm7sEALsw.jpeg</url>
            <title>Stories by nostop8 on Medium</title>
            <link>https://medium.com/@nostop8?source=rss-c75cc990c78b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 13:39:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nostop8/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[3 awesome tools for creating video guides in Ubuntu]]></title>
            <link>https://nostop8.medium.com/3-awesome-tools-for-creating-video-guides-in-ubuntu-69d1d9efa66f?source=rss-c75cc990c78b------2</link>
            <guid isPermaLink="false">https://medium.com/p/69d1d9efa66f</guid>
            <category><![CDATA[kdenlive]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[synfig]]></category>
            <category><![CDATA[kazam]]></category>
            <category><![CDATA[video-editing]]></category>
            <dc:creator><![CDATA[nostop8]]></dc:creator>
            <pubDate>Wed, 26 May 2021 19:52:05 GMT</pubDate>
            <atom:updated>2023-07-18T22:05:17.547Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5RGh2brFQ59wbP9CLD-FXw.jpeg" /></figure><p>First of all I’d like to express my praise to Linux and Ubuntu in particular. I specialize in software engineering and most of my career I’ve been working on Windows. <strong>But</strong> 2 years (in 2019) ago I’ve migrated to Linux and I do not regret about it. Of course, if you are a gamer, then obviously Linux will not work for you. But if you do not play games and use your computer specifically for the work, I think it is a perfect solution especially for software engineers where everything works extremely fast, does not consume a lot of resources, 99% of devices are supported and what is most important there’s a great choice of applications that you may use for your work.</p><p>Being a software engineer, half a year ago I needed to create a few simple video guides for one of my side projects I’ve been working on. Note: I have never worked with video before. Below I’ll list 3 apps I’ve used for creating amateur video tutorials and provide a short description of each of this app.</p><h3>1. Kazam</h3><p>First, I needed an app that can record a video from your screen. There were plenty of tools available, but I liked most of all Kazam. That’s a very-very simple app. You can select the screen area that should be recorded. Have start and stop buttons. The final video will be already optimized and in mp4 format by default. I do not have a lot of space on my laptop and this on-fly optimization was a great feature for me. But what is the most important, it could record not only the video, but also audio that is currently playing on from your laptop without any quality loss. This is a great feature for the person who has not the best voice and English accent. Plus I do not have any sound recording equipment. That’s why, I’ve used Google Text-to-Speech and while the text was spoken by Googles AI, I was recording a video on the screen.</p><p>Still, performing the demo on the screen (clicking buttons, typing the text, switching between windows and so forth) while the text is spoken is not always the easiest thing. I had to make several “shots”, record the videos over and over again just to make everything look and sound properly. That’s why I needed some video editor. So, that’s the next app I will speak about.</p><h3>2. Kdenlive</h3><p>Regarding the video editing software there’s not that great choice on Ubuntu, especially if we talk about free / open source tools. After going through few apps, I found for myself that Kdenlive is a great and very powerful software even comparing to some premium (paid) video editors. It works with any input data format like images, audios, videos (including the ones that are produced by Kazam). It supports multiple tracks where you can place your videos and audios (e.g. mp4 file is split into video and audio tracks automatically), you can easily divide any track into parts which later could be easily resized (made longer or shorter). Simple way of adding effects like fade in/out, picture in picture etc. You may also write some text on top of the picture. That’s all I needed, but there’s obviously much more. So, this tool is really highly recommended.</p><h3>3. Synfig</h3><p>This is the final tool I’ve used to create my video guides. I needed to create some animations where I have some pictures, arrows between them and all of this should interact somehow, e.g. pictures appear one after each other, resize, arrows should point from one picture to another interactively etc. Synfig is a great solution to this. BTW, in order to grab some assets I needed, I used Diagrams.net. It has pretty big library of different icons, particularly relative to software development.</p><p>Synfig reminded me a bit Macromedia (Adobe) Flash. It has a similar workflow in creating animations. Finally you can export the film to any video format and later import it into your Kdenlive project.</p><h3>Final Thoughts</h3><p>Generally, it should be enough for creating video tutorials only Kazam (screen/audio recording) and Kdenlive (video editing). Synfig is a bonus if you want to inject into your video some nice looking animation. If you are not designer (as me), you’ll also need to get some assets for those animations and Diagrams.net is a good option for this.</p><p>And finally, please, give a clap if you find those tools provided in the article as awesome as I do… or share your own alternatives in comments :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69d1d9efa66f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimizing performance of PHP app that sends an external request]]></title>
            <link>https://nostop8.medium.com/optimizing-performance-of-php-app-that-sends-an-external-request-86e2958bfece?source=rss-c75cc990c78b------2</link>
            <guid isPermaLink="false">https://medium.com/p/86e2958bfece</guid>
            <category><![CDATA[curl]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[nostop8]]></dc:creator>
            <pubDate>Mon, 24 May 2021 19:16:58 GMT</pubDate>
            <atom:updated>2021-05-25T09:03:51.255Z</atom:updated>
            <content:encoded><![CDATA[<p>I’m running web services API written in PHP and one of the endpoints during every request pings another external web service, particularly Firebase Realtime DB which in its turn can deliver notification to the client through the Websockets API. Below is the image with a rough architecture of this process:</p><figure><img alt="Architecture Diagram (initial)" src="https://cdn-images-1.medium.com/max/651/1*3ogA-xXc2l35cyr0HUYSZQ.png" /></figure><p>As you can see, any client app (browser) and any server app (some 3rd party) can send a request to the PHP endpoint, then PHP pings the Firebase endpoint and finally the Firebase notifies the client app (browser) about intercepted request.</p><h4>Web service short story</h4><p>The web service I am running is not very complicated and we can divide the operations is does into the following steps:</p><ol><li>Processing request</li><li>Doing few SQL queries including insert queries</li><li>Performing POST request to the external Firebase Realtime DB API</li><li>Providing response to the client</li></ol><p>After it was completed, I did load tests and profiling. It turned out that posting data to Firebase was taking around 1.6–2 seconds. Therefore number of requests that could be performed simultaneously to my own PHP endpoint was around 300–400 / 1 minute with the response time of more than 2 seconds (PHP app time + Firebase request time). This was a very poor result, so I started to look into improving the performance and particularly the request time to Firebase.</p><h4>A bit of side talk</h4><p>You might know that any VM is generally limited by 2 main factors: CPU and Memory. When it comes to these limitations, a very important aspect is the time (a relevant time value to our VM capacity) that is required for our application to run in a specific environment. The faster our app runs or in other words the more optimized it is, the more simultaneous instances of our app can be executed. This is especially valid for the PHP scripts.</p><h3>Optimization Iteration #0</h3><p>First of all, it turned out that the Firebase PHP SDK was making 2 requests all the time. First request to get the access token and second to actually post the data. I found out that there’s a way to use a “database secrets” which is a one-time generated token that you may use to access your Firebase DB. So I just dropped the SDK and used a direct request using CURL interface provided inside the PHP. The time to post data to Firebase decreased approximately by 1 second. So, now I could perform 700–800 requests per 1 minute and the response time was around 1–1.2 seconds. This is better than previous, but still not good enough.</p><p>The reason why Firebase request was taking so long is because PHP waits for the response from the remote server due to its synchronous code execution nature. So all the subsequent code is blocked until the response is received. This piece of functionality with Firebase notifications is not very critical to my application and in case for any reason something goes wrong during the request to Firebase, there’s no need to perform some rollback and I do not actually need to know about it immediately etc. Thus, I decided to speed up the performance by omitting the part where PHP is waiting for the response from the remote server. The PHP should just send a request and does not care about what happens afterwards.</p><h3>Optimization Iteration #1</h3><p>To solve this task I used a simple solution where you can execute external CLI commands using PHP. And yes, cURL does has a CLI interface (tool).</p><p>We may present the updated architecture on the diagram below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*kL7-2QsYW-nIn8BRBC02kw.png" /></figure><p>The PHP code combined with the cURL command looks the following way:</p><pre>$cliCommand = &lt;&lt;&lt;CODE</pre><pre>curl -k -H &quot;Content-Type: application/json&quot; -d &#39;{&quot;hello&quot;: &quot;world&quot;}&#39; -X POST https://&lt;my-db&gt;.firebaseio.com/&lt;my-endpoint&gt;.json?auth=&lt;database_secret&gt; &gt;&gt; /tmp/firebase.log 2&gt;&amp;1 &amp;</pre><pre>CODE;</pre><pre>exec($cliCommand);</pre><p>This part “<strong>&gt;&gt; /tmp/firebase.log 2&gt;&amp;1 &amp;”</strong> allows to omit the response waiting (code blocking) and instead log it inside the firebase.log file in case I need to check for any possible error later which I implemented later using a cronjob task.</p><p>This simple solution made the endpoint working almost instantly. The response time from the PHP script dropped from 1–1.2 seconds to 150–250ms and now I could perform around 1200–1300 simultaneous requests per 1 minute… Really? I was expecting a bit more. Something was definitely wrong here.</p><p>When I checked the <strong>htop</strong> tool (CPU and memory monitoring tool), I found out that during the load test, <strong>curl</strong> tools literally eats all the CPU. <strong>100% of CPU power was filled with CURL tasks</strong>. I’m not really sure why this little command line application is “so hungry” for the computation power. If you know, please drop a message in the comments below.</p><h3>Optimization Iteration #2</h3><p>Anyway, I started to search for some alternatives. Among CLI tools there’s nothing better than <strong>curl</strong>. So, I’ve decided to try another interface, particularly HTTP interface by experimenting with NodeJS (Express). Javascript is an asynchronous programming language and Node runs it very efficiently along with Express. I’ve created a small JS script using 2 extra libraries: Express and HTTP. It is basically an asynchronous proxy that listens for HTTP requests and forwards data to Firebase Realtime DB endpoint. Because we access the NodeJS script through the HTTP interface, instead of using <strong>exec()</strong> method on the PHP side, I had to switch to sockets, particularly to <strong>fsocketopen()</strong>, <strong>fwrite()</strong> and <strong>fclose()</strong>. Sockets allow to send ping requests from PHP without waiting for the response. You might want to ask why in the hell I need the NodeJS then? Well, if I use <strong>fsocketopen</strong> for sending request directly to the remote web server (Firebase) in a different network and region and for sending request to the local web server (NodeJS) that sits on the same machine — that’s 2 totally different things in terms of timing. Also I can run my local Express server without SSL, but Firebase can run using only HTTPS, thus <strong>fsocketopen</strong> would have to spend additional time to send an extra background request for the SSL handshake. Thus, yes, there’s a great benefit in using fsocketopen in order to simply open some another thread on some different local interface.</p><p>Anyway, this is the new architecture diagram I came to:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*n6Fiw975Sn8VgK8MSMOKTQ.png" /></figure><p>And here are the performance optimization results. CPU load went down from 100% to 40–50% max. The memory was almost on the same level, roughly 50–60%. The response time was 150–250 ms. And finally the number of simultaneous requests I could execute to the endpoint skyrocketed up to 5500 requests per 1 minute.</p><h4>Testing Environment</h4><p>Finally, revealing the environment I used for those tests. It is EC2 t2.micro instance (1 CPU and 1GB of memory). BTW, MySQL DB is on the separate VM instance, which saves the VM resources greatly. For load tests I was using Apache jMeter and a default thread properties, which are:</p><ul><li>number of threads (users) equals to 10</li><li>ramp-up period equals to 1 second.</li></ul><h4>Code snippets</h4><p><em>PHP script that sends request to the NodeJS script using the fsocketopen</em></p><pre>$url = &#39;<a href="http://localhost:3000/prod&#39;">http://localhost:3000/prod&#39;</a>; // URL to the NodeJS script<br>$urlParts = parse_url(https://medium.com/$url);<br>$jsonData = &#39;{&quot;hello&quot;: &quot;world&quot;}&#39;;</pre><pre>try {<br>    $fp = fsockopen($urlParts[&#39;host&#39;], $urlParts[&#39;port&#39;], $errno, $errstr, 0.1);<br>    if (!$fp) {<br>        // good place to log your error<br>    } else {<br>        $out = &quot;POST &quot; . $urlParts[&#39;path&#39;] . &quot; HTTP/1.1\r\n&quot;;<br>        $out .= &quot;Host: localhost\r\n&quot;;<br>        $out .= &quot;Content-Type: application/json\r\n&quot;;<br>        $out .= &quot;Content-Length: &quot; . strlen($jsonData) . &quot;\r\n&quot;;<br>        $out .= &quot;Connection: Close\r\n\r\n&quot;;<br>        $out .= $jsonData;<br>        fwrite($fp, $out);<br>        fclose($fp);<br>    }<br>} catch (Exception $e) {<br>    // good place to log your error<br>}</pre><p><em>NodeJS script which forwards request asynchronously to Firebase</em></p><pre>&quot;use strict&quot;;</pre><pre>const express = require(&quot;express&quot;);<br>const https = require(&quot;https&quot;);</pre><pre>const environments = {<br>  dev: {<br>    host: &quot;&lt;my-db-dev&gt;.firebaseio.com&quot;,<br>    token: &quot;&lt;my-dev-token&gt;&quot;,<br>  },<br>  prod: {<br>    host: &quot;&lt;my-db-prod&gt;.firebaseio.com&quot;,<br>    token: &quot;&lt;my-prod-token&gt;&quot;,<br>  },<br>};</pre><pre>function postFirebase(envName, data) {<br>  if (!environments[envName]) {<br>    console.log(`${envName} not found`);<br>    return;<br>  }<br>  const env = environments[envName];</pre><pre>  const options = {<br>    hostname: env.host,<br>    port: 443,<br>    path: `/&lt;my-endpoint&gt;.json?auth=${env.token}`,<br>    method: &quot;POST&quot;,<br>    timeout: 2000,<br>    headers: {<br>      &quot;Content-Type&quot;: &quot;application/json&quot;,<br>      &quot;Content-Length&quot;: data.length,<br>    },<br>  };</pre><pre>  const req = https.request(options);</pre><pre>  req.on(&quot;error&quot;, (error) =&gt; {<br>    console.error(error);<br>  });</pre><pre>  req.write(data);<br>  req.end();<br>}</pre><pre>const app = express();<br>app.use(express.json());</pre><pre>app.post(&quot;*&quot;, function (req, res) {<br>  postFirebase(req.originalUrl.substr(1), JSON.stringify(req.body));<br>  res.set(&quot;Content-Type&quot;, &quot;application/json&quot;);<br>  res.json();<br>});</pre><pre>// Listen on port 3000<br>app.listen(3000, function (err) {<br>  if (err) {<br>    throw err;<br>  }</pre><pre>  console.log(&quot;Server started on port 3000&quot;);<br>});</pre><h3>Summary</h3><p>To summarize, there’s always a room for improving and optimizing the code and its efficiency. I’ve managed to improve the time required to run the API endpoint from 2.2 seconds to 0.2 (11x times). As for the number of simultaneous requests, the improvement is more than 13x times (from 300–400 requests per minute and up to 5500). NodeJS performed much better than a CLI’s curl tool in terms of consuming CPU and memory resources. Therefore the pair of “fsocketopen() / NodeJS” works much better than “exec() / curl” if you want to initiate another thread from within the PHP to ping some external resource or web service.</p><p>Thanks for reading. Please let me know if you have an idea why curl requires so much of CPU resources to send requests comparing to NodeJS? Also it is interesting if there’s any other good option instead of NodeJS to create a small proxy over the HTTP protocol to send requests asynchronously (e.g. Python?) and do you think it can perform better? Thanks ahead for your thoughts!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86e2958bfece" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Online API Mocking Tools Comparison]]></title>
            <link>https://nostop8.medium.com/online-api-mocking-tools-comparison-9f4474a744af?source=rss-c75cc990c78b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f4474a744af</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[api-integration]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[nostop8]]></dc:creator>
            <pubDate>Mon, 16 Nov 2020 11:47:39 GMT</pubDate>
            <atom:updated>2021-02-22T10:13:39.909Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is API mocking and why do you need it?</h3><p>If you are a software engineer and you’ve used to collaborate with other developers and teams, you realize that in most cases software development process is divided into multiple stages and tasks. Dividing tasks even into smaller chunks and working on them in parallel became a philosophy of Agile methodologies like Scrum, Kanban etc. As a result, there could be a lot of tasks that have dependencies on each other.</p><p>One of the most common dependency cases in software development is that client application (web, mobile, desktop) requires API (some web services, e.g. REST) from the server side application (back-end). Obviously, nowadays front-end developer does not wait for the back-end developers to complete their part of the work like it was years ago when Waterfall was still in trend. Now client app engineers are using data mocks (stubs, fake data) in order to simulate requests to and/or responses from the server. This allows to progress not only with UI (user interface), but also with the app functionality. All this means that the dependencies between front-end and back-end are almost gone.</p><p>Same approach is also used by back-end developers when they are waiting for the 3rd party web service from other back-end developers.</p><h3>Types of Mock Data</h3><p>There are 2 types of mock data storage:</p><ul><li>Local — the mock is served directly from the local environment. It could be simply some file stored locally on a computer (e.g. *.json or *.xml file). Alternatively it could be some local application which serves data from some local web server where you manage local mock services (e.g. Mockoon, WireMock).</li><li>Online (Cloud) — the mock is stored and managed on some remote service which has its own external Domain/URL and can be reached from any location… of course, if you have an Internet connection… though it is pretty difficult to imagine that you do not have one.</li></ul><p>In this comparison article I will focus on the online tools I was using or trying to use during applications development (both client and server apps). The reason for this is that I find it a bit easier and flexible to work with. It is easier to share such mocks, control and manage them, but the main thing is because some online API mocking tools allow to capture and debug requests not only from your local machine, but also from any other 3rd party, which is useful particularly for back-end developers.</p><h3>List of compared online tools</h3><p>Below is the list of online tools to be compared. The list consists of tool name, URL and type of pricing.</p><ol><li>QuickMocker (https://quickmocker.com, Freemium)</li><li>Beeceptor (https://beeceptor.com, Freemium)</li><li>MockLab (<a href="https://get.mocklab.io/">https://get.mocklab.io</a>, Freemium)</li><li>MockAPI (https://mockapi.io, Freemium)</li><li>APIMocha (https://apimocha.com, Free)</li><li>Mocky (https://designer.mocky.io, Free)</li></ol><h3>Common Features</h3><p>All of those services listed above have following <strong>common features</strong>:</p><ul><li>Allow you to define some remote endpoint (HTTP Method + URL)</li><li>Define a custom response data (response headers, response body, response status etc)</li><li>CORS support (required for browser apps)</li></ul><p>Except for this, I want to list their free features I have discovered on the date of this article one by one and at the end provide a comparison table which I hope will be useful for you when choosing the right tool for yourself.</p><p>So, let’s get started!</p><figure><img alt="QuickMocker — Online API Mocking Tool" src="https://cdn-images-1.medium.com/max/300/1*D5Z359TezRnCiBHd1-lNVA.png" /></figure><h3>1. QuickMocker</h3><p>I have discovered QuickMocker recently, but for me it became most helpful. It supports almost all features that others have, has a simple and modern user interface and additionally it offers unique features. QuickMocker<strong> </strong>has a Free and also two premium subscription plans that have higher quotas for endpoints and requests and the cost relatively cheap, something like few bucks.</p><p>Below are the features that QuickMocker supports in a free version:</p><ul><li>Private management of endpoints / rules</li><li>Live (instant) capturing and debugging of requests (no need for page refresh)</li><li>Requests log (72 hours in free version)</li><li>Dynamic URLs (Regular Expressions)</li><li>Multiple HTTP methods per endpoint</li><li>Response templating (supports more than 100 shortcodes for contextual, random and fake data)</li><li>Endpoints prioritization (manual sorting or reordering of endpoints)</li><li>Request Proxy</li><li>Endpoint Access Restrictions (IP Address / Authorization Header)</li><li>Import of endpoints from OpenAPI (Swagger) Specifications</li><li><strong>Local Forwarder -</strong> this is the main unique feature for me, because it allows to forward external request from some 3rd party (e.g. webhook from Stripe, Paypal, BitBucket etc) to your localhost application. So now when I develop and test integration with 3rd party that sends some notifications to my server app, I go to QuickMocker, add my localhost app URL (e.g. myapp.localhost) and external requests are magically delivered to the application that is hosted on my local machine only (meaning the app does not have any public URL or even IP address). You can also forward requests to your localhost app any time you want. Just define the Forwarder URL. Learn more about real world sample in this article: <a href="https://bit.ly/2UtrlNR">https://bit.ly/2UtrlNR</a></li></ul><p>Finally this QuickMocker does provide a support over email, even when I was using a free subscription plan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/85/1*CiPahgxaDA0qH9z9XkKLmw.png" /></figure><h3>2. Beeceptor</h3><p>Me and my colleagues have been using this tool pretty heavy in the past. It still seems to be one of the most popular among developers community, but in my opinion it has already very outdated UI/UX and on the current date it offers much less than other similar tools. It has one free and two premium subscription plans with some higher quotas and extra features.</p><p>Below are the main free features:</p><ul><li>Live (instant) capturing and debugging of requests (no need for page refresh)</li><li>Dynamic URLs (limited support for only few patterns)</li><li>Proxy Requests</li></ul><p>If you want to manage endpoints / rules privately, do some templating of response and get some support, you will have to buy one of the premium subscriptions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*6Id8n211NCa2RvuzYyOR3Q.png" /></figure><h3>3. MockLab</h3><p>Another interesting tool, which is based on a local stubbing tool WireMock. It has a freemium pricing model with one free and four paid subscription plans. I won’t go deep into the paid features because I have not used them.</p><p>The main free features are:</p><ul><li>Private management of endpoints / rules</li><li>Manual capturing and debugging of requests (requires to press refresh button)</li><li>Requests log is stored only 4 hours</li><li>Dynamic URLs (including Regular Expressions)</li><li>Response templating</li><li>Proxy Requests</li><li>Endpoint Access Restrictions (Authorization Header, HTTP Authentication)</li><li>Import of Open API rules (in beta)</li></ul><p>Also they have support through email and live chat, which pretty handy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/100/1*oZD5F17UiKEhTE1b4sp5xA.png" /></figure><h3>4. MockAPI</h3><p>This is another freemium tool with one free and two premium subscriptions. The only difference between the free and paid version is the number of resources. This tool has a very interesting approach in data mocking and templating. On the other hand it lacks the requests interception / debugging. Below I will list its features:</p><ul><li>Private management of endpoints / rules</li><li>Dynamic URLs (only entity ID)</li><li>An interesting solution to response templating comparing to other tools</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*BmgtgxRctLDwt5YFJAkTOg.png" /></figure><h3>5. APIMocha</h3><p>This is a free only tool without any premium subscriptions and therefore there’s no user authentication. Endpoint is available for 30 days and will be removed if there’s no activity during 30 days. You are able to edit your endpoint only from the same computer + browser that you used to create the endpoint and in case you clear the site storage, the endpoint management is gone and you’ll have to start over.</p><p>The main features are:</p><ul><li>Live (instant) capturing and debugging of requests (no need for page refresh)</li><li>Import of Open API rules</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*lH6ICA3lXl9nGiVN24qkSg.png" /></figure><h3>6. Mocky</h3><p>Very simple free only tool. It does not have any authentication and therefore no private management of the endpoints. You cannot even edit your existing endpoint like you could do in the previous mocking tool. No requests capturing and debugging available. Still, this is one of the most popular online mocking tools.</p><h3>Comparison table</h3><p>Below, as promised, I have prepared the comparison table of free features of the online API mocking tools that was reviewed above:</p><figure><img alt="Comparison Table of free online API mocking tools" src="https://cdn-images-1.medium.com/max/1024/1*SAn2XDdlB1ue2bvIJl_PSg.png" /><figcaption>Comparison Table of Free Online API Mocking Tools</figcaption></figure><p>I hope after reading this article you know more about the “world of Online API Mocking” and it will be easier for you to jump in and use online data mocks for the software development and testing. My own choice is <a href="https://quickmocker.com/">QuickMocker</a> for the moment because it provides 90% of what other tools have and it has some unique features like Local Forwarder. It seem to be in an active development because new features are added regularly and any bugs I’ve noticed are resolved quickly. In case of any troubles the support is very responsive.</p><p>And by the way, it will be interesting to hear your thoughts on the Online API Mocking Tools described here and/or if you use any other. So looking forward for your comments and feedback.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f4474a744af" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Forward events and User ID from Google Tag manager to Google Analytics]]></title>
            <link>https://nostop8.medium.com/forward-events-and-user-id-from-google-tag-manager-to-google-analytics-c029e0593c41?source=rss-c75cc990c78b------2</link>
            <guid isPermaLink="false">https://medium.com/p/c029e0593c41</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[google-tag-manager]]></category>
            <category><![CDATA[web-marketing]]></category>
            <category><![CDATA[marketing-tools]]></category>
            <category><![CDATA[google-analytics]]></category>
            <dc:creator><![CDATA[nostop8]]></dc:creator>
            <pubDate>Wed, 11 Nov 2020 13:15:48 GMT</pubDate>
            <atom:updated>2020-11-11T13:15:48.296Z</atom:updated>
            <content:encoded><![CDATA[<h3>Forward Events and User ID from Google Tag Manager to Google Analytics</h3><p>Majority of software developers (if not all) are familiar with the Google Analytics (GA) and probably did integrate this marketing tool at least once in a lifetime. GA is the most popular tool for tracking web page views and therefore the most popular tool to integrate among the web developers. According to many usage stats sites, more than 50% of all web sites use GA. And Google won’t stand back, unless it replaces GA with some more modern tool.</p><p>Some of you were integrating other Google marketing services like Google Ads, Google Optimize, Google Surveys and many other. Or maybe Twitter Website Tag and tons of other non-Google marketing services? But what’s common across all of those services? And the answer is simply <strong>Google Tag Manager</strong> (GTM).</p><p>All of the marketing services require separate modules, extensions, plugins, javascript libraries and so forth. If your project owners have a big appetite to marketing tools, you might end-up with the tons of scripts connected separately to your web site, integration of this marketing non-sense in the codebase or worth somewhere on the database level (if this is some CMS based system). All of this marketing stuff will end-up mixed with your codebase, admin panel and so forth. As result it will make your developer’s life more difficult. Some of you might be OK with this and its cool, I’m not judging :) But for me, the choice was obvious as soon as I realized that I need to connect more than 2 Google marketing services and moreover modules that are responsible for the integration of those services <strong>conflict each other (</strong>yeah, this case is pretty much possible too<strong>)</strong>.</p><p>Particularly my problem was that I had already Google Analytics on the site and it was using a lot of different events triggered in the code, e.g. when user registers, when user creates/edits/deletes project and many other internal entities. In case you are familiar with GA events you know that each event can consist of the following params: <em>action</em>, <em>category</em>, <em>label</em> and <em>value</em>. So I had the following GA event calls all around the application similar to this:</p><pre>this.gaService.event(&#39;&lt;action&gt;&#39;, &#39;&lt;category&gt;&#39;, &#39;&lt;label&gt;&#39;, &#39;&lt;value&gt;&#39;);</pre><p>And the event method looked similarly to this:</p><pre>public function event(action, category, label, value) {<br> if (window[&#39;<strong>gtag</strong>&#39;]) {<br>  window[&#39;<strong>gtag</strong>&#39;](&#39;event&#39;, action, {<br>   &#39;event_category&#39;: category,<br>   &#39;event_label&#39;: label,<br>   &#39;value&#39;: value<br>  });<br> }<br>}</pre><p>After I have replaced GA tracking code with the GTM tracking code obviously there was no gtag method anymore. GTM has its own events system, which is not related to the GA events at all. So what you can do is send a notification from your app to GTM, and GTM will basically forward a notification to the GA. This idea was simple, but it took me some time to realize how to implement this events forwarding in a simple way too.</p><p>Below are 3 images which show how you can progress in integrating marketing services gradually starting with direct integration of the marketing services and ending with the GTM as a gateway for all other marketing services:</p><figure><img alt="Direct WebSite/App and Google Analytics integration" src="https://cdn-images-1.medium.com/max/491/1*XU2FzsF5n_edCC9w6J3lWg.png" /><figcaption>1.1 Direct integration with Google Analytics</figcaption></figure><figure><img alt="WebSite/App and Google Analytics integration through Google Tag Manager" src="https://cdn-images-1.medium.com/max/678/1*kagyJJp4xDdYuo-pGiOlmQ.png" /><figcaption>1.2 Integration of Google Analytics through Google Tag Manager</figcaption></figure><figure><img alt="WebSite/App and marketing services integration through Google Tag Manager" src="https://cdn-images-1.medium.com/max/678/1*yhjY3e29l7YbJvvsBzyVGg.png" /><figcaption>1.3 Integration of marketing services through Google Tag Manager</figcaption></figure><p>Now lets try to progress from diagram 1.1 to diagram 1.2.</p><p>First, we obviously need to replace our GA tracking code with GTM tracking code. If you do not have it yet, go to GTM (<a href="https://tagmanager.google.com/">https://tagmanager.google.com/</a>) and grab it by clicking your GTW ID:</p><figure><img alt="Google tag manager tracking code" src="https://cdn-images-1.medium.com/max/740/1*yJfBHi5nn_M8k8vTaQn-0w.png" /></figure><p>Afterwards you need to create 4 variables of Data Layer type with the following names:</p><ul><li>gaAction</li><li>gaCategory</li><li>gaLabel</li><li>gaValue</li></ul><p>See sample of creating gaAction variable below:</p><figure><img alt="Google tag manager create variable" src="https://cdn-images-1.medium.com/max/1024/1*gZ9zizE_Mc8ATLeZm--UIw.png" /></figure><p>Do the same for the rest variables. Eventually you should have a variables list like on the image below:</p><figure><img alt="Google tag manager variables list" src="https://cdn-images-1.medium.com/max/1024/1*CXcY1Vxkoe-pNhULGJkC9g.png" /></figure><p>All 4 GTM variables names correspond to the parameters that are passed to the GA event (see gtag method above in the article).</p><p>The next step is to create a GTM Trigger with a custom event. Go to Triggers and create new “Custom GA Event” trigger as on the image below:</p><figure><img alt="Google tag manager triggers (events)" src="https://cdn-images-1.medium.com/max/923/1*7bdka7eMg7SQrD_tS6tf2g.png" /></figure><p>Make sure to select Custom Event as a Trigger Type. And inside the Event Name enter gaEvent.</p><p>Now you need to create a new Google Analytics: Universal Analytics Tag in GTM as on the image below:</p><figure><img alt="Google tag manager — create tag" src="https://cdn-images-1.medium.com/max/767/1*9oFE1XdYbPUNrp73OJ11dg.png" /></figure><p>Make sure to select Event as a Track Type. Afterwards you will be presented with 4 fields (category, action, label and value) where you can provide the corresponding variables we have created in the previous step. If you haven’t configured your Google Analytics settings, that’s the right time to do it. And finally select our “Custom GA Event” as a Firing Trigger at the bottom of the page.</p><p>After you saved this new tag, don’t forget to publish the updates (I forgot to do this often in GTM).</p><figure><img alt="Google tag manager — publish changes" src="https://cdn-images-1.medium.com/max/740/1*UciZMrFkJuP8ahASU1J68w.png" /></figure><p>Finally lets add GTM event triggering code into our website / app (or replace the GA code as it was in my case). My code has turned into:</p><pre>public function event(action, category, label, value) {<br> if (window[&#39;<strong>dataLayer</strong>&#39;]) {<br>  window[&#39;<strong>dataLayer</strong>&#39;].push({<br>      &#39;event&#39;: &#39;gaEvent&#39;,<br>      &#39;gaAction&#39;: action,<br>      &#39;gaCategory&#39;: category,<br>      &#39;gaLabel&#39;: label,<br>      &#39;gaValue&#39;: value,<br>  });<br> }<br>}</pre><p>You’ll probably have something similar too.</p><p>Alright. Last but not least, if you want to track your User ID as you did when you used GA directly, you need first of all to create another GTM Data Layer variable. Lets call if userId :</p><figure><img alt="Google tag manager — create userId variable" src="https://cdn-images-1.medium.com/max/486/1*GDv6vvKT-SYe51NX23RlWA.png" /></figure><p>And now go to your Google Analytics variable (yes, during Google Analytics configuration in GTM, you should have created a corresponding variable for it) and do the mapping between GA userId and the GTM userId variable we have created in the previous step. See the image below:</p><figure><img alt="Google tag manager — map userId with Google Analytics" src="https://cdn-images-1.medium.com/max/1024/1*Bexy1u1lE7zvlpR61g6EKA.png" /></figure><p>Now that’s it. Hope all makes sense. Write your feedback and comments if you have them. Cheers ;)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c029e0593c41" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integration of  Fondy (3rd party service) webhooks using QuickMocker and its Local Forwarder]]></title>
            <link>https://nostop8.medium.com/integration-of-fondy-3rd-party-service-webhooks-using-quickmocker-and-its-local-forwarder-fe03ee9041?source=rss-c75cc990c78b------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe03ee9041</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[webhooks]]></category>
            <category><![CDATA[quickmocker]]></category>
            <category><![CDATA[fondy]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[nostop8]]></dc:creator>
            <pubDate>Sat, 26 Sep 2020 20:24:21 GMT</pubDate>
            <atom:updated>2020-09-26T20:24:21.840Z</atom:updated>
            <content:encoded><![CDATA[<h3>Integration of Fondy (3rd party service) webhooks using QuickMocker and its Local Forwarder</h3><p>So you are a developer and you’ve got yet another task to integrate some 3rd party into your app? E.g. some payment system like Stripe, PayPal or maybe some meeting rooms like Zoom, GoTo or whatever else you can imagine to integrate? Nowadays all of such services provide API not only as an interface for receiving requests from clients (e.g. your web app), but also they can make reverse requests to your app in order to notify the client immediately about some event on the 3-rd party side. This kind of reverse requests as you might guess already are called Webhooks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*4BLqHL9R-fch-YP5Bbdyjg.png" /><figcaption>Diagram of the interaction between app and 3rd Party</figcaption></figure><p>As a sample we will be integrating Fondy (a payment service provider) into our app. Particularly in this sample we need to integrate the instant notification (webhook) to our application about payment completion. On the server side we will use PHP code samples and on the client side it will be Javascript.</p><p>But first of all you’ll need to register your <a href="https://fondy.eu/">Fondy</a> account. Then go to the Merchant Settings and grab your Merchant ID and Payment Key (also called “secret key” in the API doc):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*im1X7nF-ljlG2dsgBjk1Rw.png" /></figure><p>Secondly go and get a free <a href="https://quickmocker.com/">QuickMocker</a> account. Create a new project with a suggested random subdomain. Go inside the project and copy your endpoint (subdomain) URL:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ulNCJZv9nqxQFK-FvQfgyg.png" /><figcaption>QuickMocker’s Project Domain and Endpoints</figcaption></figure><p><em>Please note that by default the initial wildcard endpoint can intercept any request made to any URL of the project. It will respond with 404 status code by default, but you can change this behavior if you want.</em></p><p>Now we will build a simple PHP web service (or simply script) with the help of Fondy PHP SDK (v2) that will generate for us a one-time token that we’ll use for creating a payment form. In case you use composer, you can add Fondy PHP SDK using this command:</p><pre>composer require cloudipsp/php-sdk-v2</pre><p>Alternatively you might download or clone it. See yourself more here: <a href="https://packagist.org/packages/cloudipsp/php-sdk-v2">https://packagist.org/packages/cloudipsp/php-sdk-v2</a></p><p>Later we will use this token to securely generate order form on the client side using Fondy JavaScript SDK. Huh… a lot of words which might sound as a non-sense :) But I hope they will start making sense if you look at the code sample below:</p><pre>&lt;?php</pre><pre>include &#39;vendor/autoload.php&#39;; // in case you use composer</pre><pre>use Cloudipsp\Configuration;<br>use Cloudipsp\Checkout;</pre><pre>Configuration::setMerchantId(&#39;&lt;fondyMerchantID&gt;&#39;);<br>Configuration::setSecretKey(&#39;&lt;fondyPaymentKey&gt;&#39;);<br>Configuration::setApiVersion(&#39;2.0&#39;);</pre><pre>$request = [<br><strong>&#39;order_id&#39; =&gt; time(),</strong><br>&#39;currency&#39; =&gt; &#39;USD&#39;,<br>&#39;merchant_id&#39; =&gt; &#39;&lt;fondyMerchantID&gt;&#39;,<br><strong>&#39;order_desc&#39; =&gt; &#39;QuickMocker Test Order&#39;,</strong><br><strong>&#39;product_id&#39; =&gt; &#39;test&#39;,</strong><br>&#39;amount&#39; =&gt; 1, // equals 1 cent<br>&#39;required_rectoken&#39; =&gt; &#39;Y&#39;, // might use this if you want to charge your customers later without customer interaction, e.g. for recurring payments<br><strong>&#39;server_callback_url&#39; =&gt; &#39;</strong><a href="https://qafu2mppt7.api.quickmocker.com&/#39;"><strong>https://qafu2mppt7.api.quickmocker.com&#39;</strong></a><strong>, // this is where our QuickMocker endpoint gets inserted, change it to your own.</strong><br>];</pre><pre>$response = Checkout::token($request);<br>$data = $response-&gt;getData();<br>echo $data[&#39;token&#39;];</pre><p>So the script above generates for us a one-time token that we can use in order to create a payment form in the client app. This form will already get the payment amount that we have set on the server side (so nobody can replace it in the client app). But the main thing is that this payment is linked with our internal order ID and product ID which again cannot be hijacked.</p><p>Now lets create a simple JS client app which we can try out on some online service like JsFiddle, where we’ll use our token generated by the PHP script we had written above. You might customize the look of the payment form using CSS. You can even hide some fields like email, in case you do not want allowing user to change it (remember we have an order ID which can be linked with the user and its email in our app’s database).<br>So, first of all you have to include following JS and CSS file in your app provided by Fondy CDN:</p><pre><a href="https://pay.fondy.eu/latest/checkout.js">https://pay.fondy.eu/latest/checkout.js</a><br>https://pay.fondy.eu/latest/checkout.css</pre><p>And below are all the parts of the app, separately (HTML, JS and CSS):</p><p><strong>HTML Part:</strong></p><pre>&lt;!-- Only one container needed to place the fondy payment form --&gt;<br>&lt;div id=&quot;checkout-container&quot;&gt;&lt;/div&gt;</pre><p><strong>JavaScript Part:</strong></p><pre>var options = {<br>  options: {<br>    fullScreen: true,<br>    fee: true,<br>    title: &#39;QuickMocker Test&#39;,<br>    email: true,<br>    link: &#39;<a href="https://quickmocker.com&/#39;">https://quickmocker.com&#39;</a>,<br>    tooltip: true,<br>  },<br>  params: {<br>    token: &#39;7d6c8299fc906793fc1b3036dc9722d826eb3b60&#39;, // place your token here to see checkout form instead of payment is approved<br>    email: &#39;<a href="/service/mailto:your.email@testemail.com">your.email@testemail.com</a>&#39;,<br>  },<br>};</pre><pre>window.fondy(&#39;#checkout-container&#39;, options).$on(&quot;success&quot;, (model) =&gt; {<br>  var order_status = model.attr(&quot;order.order_data.order_status&quot;);<br>  if (order_status == &quot;approved&quot;) {<br>    alert(&#39;Your payment was successfully processed.&#39;);<br>  }<br>}).$on(&quot;error&quot;, function (model) {<br> var response_description = model.attr(&quot;error.message&quot;);<br> alert(&#39;There was a problem with your payment. Details: &#39; + response_description);<br>});</pre><p><strong>CSS Part:</strong></p><pre>/* Sample styles for the fondy payment form */<br>.f-header {<br>  background: #d5ecff;<br>}<br>.f-wrapper {<br>  background: #daf7d8 !important;<br>}</pre><p>All of the parts together on the <a href="https://jsfiddle.net/wf64gbr2/">JSFiddle here</a>:<br><a href="https://jsfiddle.net/wf64gbr2/">https://jsfiddle.net/wf64gbr2/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OXKh9PkrFcm8U3bUIrMJPw.png" /><figcaption>Screenshot from JSFiddle of all parts together including some additional comments</figcaption></figure><p>In order to make a payment, lets use test credit cards, which you may find at this URL: <a href="https://docs.fondy.eu/en/docs/page/2/">https://docs.fondy.eu/en/docs/page/2/</a> . Copy the card number, provide any month, year and CVV code you want and hit Pay Now button.<br>Right after the payment is completed successfully, QuickMocker endpoint immediately receives a request (webhook) from Fondy:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XxIgnrSGzQwyPzWiSpxaJQ.png" /><figcaption>Notification about new requests to the endpoint</figcaption></figure><p>Click on the Requests Log tab, and you’ll see the list of the requests that was done to your endpoint. Unfold the top request which is the latest as on the screenshot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_YADKSwhp5f8e8wWgAmgVw.png" /><figcaption>Fondy webhook request view</figcaption></figure><p><em>By the way, we did not add any custom endpoint to receive Fondy webhooks, so it is intercepted by QuickMocker using the initial wildcard endpoint which responds with 404 status code by default. Because of this Fondy might send to you several webhook requests with the same payment result data. You can add another endpoint for the Fondy webhook or else simply change status code of the initial endpoint to 200.</em></p><p>Anyway, as you can see on the screenshot above, the data is sent as a base64. If you decode it you will see a JSON similar to this:</p><pre>{<br>   &quot;order&quot;:{<br>      &quot;rrn&quot;:&quot;&quot;,<br>      &quot;masked_card&quot;:&quot;444455XXXXXX6666&quot;,<br>      &quot;sender_cell_phone&quot;:&quot;&quot;,<br>      &quot;response_status&quot;:&quot;success&quot;,<br>      &quot;sender_account&quot;:&quot;&quot;,<br>      &quot;fee&quot;:&quot;&quot;,<br>      &quot;rectoken_lifetime&quot;:&quot;01.01.2034 00:00:00&quot;,<br>      &quot;reversal_amount&quot;:&quot;0&quot;,<br>      &quot;settlement_amount&quot;:&quot;0&quot;,<br>      &quot;actual_amount&quot;:&quot;8442&quot;,<br>      &quot;order_status&quot;:&quot;approved&quot;,<br>      &quot;response_description&quot;:&quot;&quot;,<br>      &quot;verification_status&quot;:&quot;&quot;,<br>      &quot;order_time&quot;:&quot;24.09.2020 17:41:32&quot;,<br>      &quot;order_id&quot;:&quot;1600980123&quot;,<br>      &quot;parent_order_id&quot;:&quot;&quot;,<br>      &quot;merchant_data&quot;:&quot;&quot;,<br>      &quot;tran_type&quot;:&quot;purchase&quot;,<br>      &quot;eci&quot;:&quot;7&quot;,<br>      &quot;settlement_date&quot;:&quot;&quot;,<br>      &quot;payment_system&quot;:&quot;card&quot;,<br>      &quot;rectoken&quot;:&quot;e07e0989bcdffaa446909438b367c136cc90bac7&quot;,<br>      &quot;approval_code&quot;:&quot;478450&quot;,<br>      &quot;merchant_id&quot;:1436164,<br>      &quot;settlement_currency&quot;:&quot;&quot;,<br>      &quot;payment_id&quot;:272767812,<br>      &quot;product_id&quot;:&quot;test&quot;,<br>      &quot;currency&quot;:&quot;USD&quot;,<br>      &quot;card_bin&quot;:444455,<br>      &quot;response_code&quot;:&quot;&quot;,<br>      &quot;card_type&quot;:&quot;VISA&quot;,<br>      &quot;amount&quot;:&quot;1&quot;,<br>      &quot;sender_email&quot;:&quot;<a href="/service/mailto:your.email@testemail.com">your.email@testemail.com</a>&quot;<br>   }<br>}</pre><p>In order to make sure that this data is not spoofed, we need to validate it against the signature which was sent inside the webhook along with the data.</p><pre>&lt;?php</pre><pre>include &#39;vendor/autoload.php&#39;; // in case you use composer</pre><pre>use Cloudipsp\Configuration;<br>use Cloudipsp\Response\Response;</pre><pre>$requestBody = file_get_contents(&#39;php://input&#39;);<br>$requestData = json_decode($requestBody, true);</pre><pre>Configuration::setMerchantId(&#39;&lt;fondyMerchantID&gt;&#39;);<br>Configuration::setSecretKey(&#39;&lt;fondyPaymentKey&gt;&#39;);<br>Configuration::setApiVersion(&#39;2.0&#39;);</pre><pre>$response = new Response([<br>    &#39;response&#39; =&gt; json_encode([<br>        &#39;response&#39; =&gt; $requestData,<br>    ], 320),<br>]);</pre><pre>if (!$response-&gt;isValid()) {<br>    print &quot;Error: Invalid data&quot;;<br>} else {<br>    $order = $response-&gt;getData();<br>    print &quot;Success: Order ID: &quot; . $order[&#39;order_id&#39;];<br>}</pre><p>So we have successfully captured the webhook from 3-rd party service using <a href="https://quickmocker.com/">QuickMocker API mocking tool</a>. Knowing the webhook request data allows us to create a proper web service that can handle this data and complete our order on the server side of the app (e.g. mark the order in the database as paid, save the `rectoken` for possible future charges of the customer etc). So such API mocking tools like QuickMocker are very helpful in a reverse integration with 3-rd parties without having to put our app into public, which means our app does not need to have some public DNS or IP address during the development stage.</p><p>The only inconvenience here you might think is that if we want to test our code, we still have to mimic the request to our local server app with that data captured by QuickMocker using some tool like Postman which adds a bit of overhead here in a form of a manual intervention during the testing. But wait… except of capturing requests from remote services, QuickMocker can also work as a local client forwarder, which means while QuickMocker is opened in your browser and while it receives the requests from the outside, it can also forward those requests to your “localhost” server app.</p><p>How to setup forwarder? Simply set your local development server app URL, which will receive the payment completion webhook from the fondy (e.g. <a href="http://localhost/fondy-payment-completed"><em>http://localhost/fondy-payment-completed</em></a>). To do this click on the Set Local Forwarder button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q4lFNMYA4AFcR9CC3GIFDA.png" /><figcaption>Set Local Forwarder</figcaption></figure><p>And in the modal provide URL. Note: in case your development server app is using insecure protocol (HTTP), you will need to allow this in your browser settings. Read more about allowing your browser to send HTTP request from HTTPS site here: <a href="https://docs.adobe.com/content/help/en/target/using/experiences/vec/troubleshoot-composer/mixed-content.html">https://docs.adobe.com/content/help/en/target/using/experiences/vec/troubleshoot-composer/mixed-content.html</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*VSQEZPnwm6UX4IE4KUkP6A.png" /><figcaption>Provide URL you want the request to be forwarded to</figcaption></figure><p>Click Set and you are done. Now the requests will be forwarded to your local app URL and you are all set to receive webhooks directly to your app while developing, debugging, testing and so on. Please note that Local Forwarder URL won’t be saved with your project. As soon as you leave the Requests Log tab, the URL will be gone. So you will have to set it once again if you want to continue “forwarding”.</p><p>BTW, there’s a small FAQ which should provide all info you need for <a href="https://quickmocker.com/faq#forwarder">Local Forwarder</a> usage: <a href="https://quickmocker.com/faq#forwarder">https://quickmocker.com/faq#forwarder</a></p><p>Finally, after you set Local Forwarder URL, you’ll also notice another tab Forwarder Response in the request panel:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EcoefVDXff16WkKBkHiyMQ.png" /><figcaption>Forwarder Response tab</figcaption></figure><p>Our app has received a forwarded webhook and we can also preview the response of our app in the additional tab as on the screenshot above.</p><p>To sum up: an API mocking (fake) tools like QuickMocker could be really helpful while integrating 3rd party services and particularly reverse requests called webhooks. With the help of Local Forwarder feature that is provided by QuickMocker, the integration of webhooks becomes even more seamless without any need to make your local server application public to the world.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe03ee9041" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Serving Cached Angular Universal (SSR) Web App through Apache Proxy]]></title>
            <link>https://nostop8.medium.com/serving-cached-angular-universal-ssr-web-app-through-apache-proxy-e8fe2e4b3fff?source=rss-c75cc990c78b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8fe2e4b3fff</guid>
            <category><![CDATA[apache-proxy]]></category>
            <category><![CDATA[angular-universal]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[angular-ssr]]></category>
            <category><![CDATA[apache-cache]]></category>
            <dc:creator><![CDATA[nostop8]]></dc:creator>
            <pubDate>Fri, 10 Jul 2020 21:52:24 GMT</pubDate>
            <atom:updated>2020-07-10T23:03:01.220Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently we have completed our new start-up project. Right from the beginning we’ve made a decision that all the front-end will be Angular including public pages like home, blog etc. Obviously we were regretting about our decision when we realized how many problems we have, taking into account SEO and stack of our server-side technologies :) But it was too late to step back! So we went forward and I think the experience we’ve gained is worth it. That’s why I want to share with you and hopefully it will be helpful for you.</p><p>The main reason why we started all of this Angular SSR (Server-Side Rendering) thing is the SEO as you might guess already. We realize that GoogleBot can index SPA (Single Page Application) more or less properly for several years already. But there’s not only holy Google around us (You might want to read more about this problem here more detailed <a href="https://snipcart.com/spa-seo">https://snipcart.com/spa-seo</a>). And we really wanted our start-up to be indexed properly by any search engine, which by the way will make your rankings higher in the Google Search too (a sort of butterfly effect… huh).</p><p>We had a clear vision of what we want to achieve. We can formulate our goal using very simple sentence:</p><blockquote>“<strong>to serve fully server-rendered public pages with a very short response (page load) time</strong>”.</blockquote><p>Here’s the diagram of our expected request flow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*q9A5P7B6vq_RDXt_95yX3w.png" /></figure><p>First of all we had to enable this Universal Application. It turned out to be a very simple task, which you can basically do with one command (more details here <a href="https://angular.io/guide/universal">https://angular.io/guide/universal</a>):</p><pre>ng add @nguniversal/express-engine</pre><p>Then we deployed our app to the remote server. BTW, here’s the short list of of server-side technologies stack that we are using:</p><ul><li>AWS EC2 instance with an official CentOS 7 image</li><li>Apache 2.4 Web Server with mod_proxy</li><li>Node and Angular-CLI in order to run our Angular app</li><li>PM2 (Node.js app manager)</li></ul><p>Enabling Apache Proxy was also a matter of few Apache directives, which you’ll see in the VirtualHost file a bit lower.</p><p>But from the start we’ve found out that Angular SSR is a very slow thing. Our home page was loading for around 5–6 seconds, which is not acceptable for us. Obviously we had to enable a caching.</p><p>We needed some simple caching, which would cache our site pages based on the URL (meaning URL would be a cache key). OK, there’s a prerender from Angular Universal, which can generate a folder structure like your routes with HTML rendered in index.html file for each of the route. This is a sort of caching for your pages. But there are some troubles with dynamic routes described in the article by Sam Vloeberghs in this <a href="https://samvloeberghs.be/posts/angular-v9-universal-ssr-and-prerendering-out-of-the-box">article</a>, that we can shorten to the following sentence: “you need to define and maintain separately all the URLs for your dynamic routes”. There’s also a way to perform caching that we need on the level of Node app. This is also described by Sam Vloeberghs in another <a href="https://samvloeberghs.be/posts/creating-a-simple-memory-cache-for-your-angular-universal-website-or-application">article</a>. Still for us it was obvious that the most efficient for our case would be to enable cache on the level of Apache web server. This means that as soon as the web resource is cached by Apache, there’s no need to proxy requests further to Node app, it will be returned directly from Apache cache.</p><p>So the idea was simple, but it turned out to be a real pain. Apache cache behaved not the way we expected. It turned out that it is very sensitive to client directives related to cache. In other words Apache cache behavior is extremely dependent on the client. And the most frustrating thing was that there are multiple directives that are supposed to handle this problem, all of them are described in many articles on the web, but none of this helped in our case. For some reason from some devices / browsers Apache was returning a non-cached version of the pages, which means it was requesting Node app and resulted in a very slow page load. Our expectation was that as soon as any client requests a specific page, the result will be cached by Apache and the subsequent requests to the same page from any other client would return a cached version of the page. But for some reason most of the clients were getting its own cache version, which means each client had to wait for 5–6 seconds in order to load the home page for the first time. And this was really bad…</p><p>So we started to debug the issue using Postman and by enabling/disabling some headers of requests. It turned out that except for the standard cache headers (Cache-Control, Pragma, Expires), Apache Caching also checks for few other headers, which are <strong>If-Modified-Since</strong> and <strong>If-None-Match</strong>. Particularly in our case <strong>If-None-Match </strong>was an issue. This client cache header works in tandem with <strong>ETag</strong> header provided by the server. None of the Apache cache directives like <strong>CacheIgnoreCacheControl</strong> or <strong>CacheIgnoreHeaders</strong> can turn off this ETag check. The only thing that had an effect to this problem was “<strong>RequestHeader unset If-None-Match”</strong>. So after around 1 day of struggling and playing around with Apache Proxy and Cache, we’ve found a simple solution that made all things to work as expected.</p><p>Please see below our part of our Apache Virtual Host file:</p><pre>&lt;IfModule mod_ssl.c&gt;</pre><pre>&lt;VirtualHost *:443&gt;</pre><pre>ServerName quickmocker.com<br>DocumentRoot /path/to/your/site</pre><pre>&lt;Location &quot;/&quot;&gt;<br>AllowMethods GET<br>&lt;/Location&gt;</pre><pre><strong># Make sure all the headers that can force apache cache to return non-cached version are dropped</strong></pre><pre><em>RequestHeader unset Expires<br>RequestHeader unset Cache-Control<br>RequestHeader unset Pragma<br>RequestHeader unset If-Modified-Since<br></em><strong><em>RequestHeader unset If-None-Match</em></strong></pre><pre>CacheQuickHandler off<br>CacheIgnoreNoLastMod On<br>CacheDefaultExpire 31536000</pre><pre>CacheIgnoreCacheControl On<br>CacheIgnoreHeaders Set-Cookie Cookie Expires Cache-Control Pragma If-None-Match If-Modified-Since<br>CacheHeader on<br>CacheLock on</pre><pre><strong># Enable gzipping of html,css,js etc. Do not do this for non-vector images!</strong></pre><pre><em>SetOutputFilter CACHE<br>AddOutputFilterByType DEFLATE text/html text/plain text/css application/javascript application/rss+xml text/xml image/svg+xml</em></pre><pre>CacheRoot /path/to/your/cache/folder<br>CacheEnable disk /<br>CacheDirLevels 2<br>CacheDirLength 1<br>CacheMaxFileSize 4000000</pre><pre><strong># Make sure to disable client cache for text/html and to enable for all other mime types</strong></pre><pre><em>ExpiresActive On<br></em><strong><em>ExpiresByType text/html &quot;access plus 1 second&quot;</em></strong><em><br>ExpiresByType application/json &quot;access plus 1 second&quot;<br>ExpiresByType application/javascript &quot;access plus 1 year&quot;<br>ExpiresByType text/css &quot;access plus 1 year&quot;<br>ExpiresByType image/png &quot;access plus 1 year&quot;<br>ExpiresByType image/jpeg &quot;access plus 1 year&quot;</em></pre><pre># Proxy request to node.js app if cache was not found</pre><pre>ProxyPreserveHost On<br>ProxyRequests Off<br>ProxyPass /sitemap.xml !<br>ProxyPass /robots.txt !<br>ProxyPass / http://localhost:4000/</pre><pre>...</pre><pre>&lt;/VirtualHost&gt;</pre><pre>&lt;/IfModule&gt;</pre><p>Additional tips! As you may see above, we enable gzipping for all the content that could be gzipped (text like html,css,js or vector image). And the most important thing is that we need to force the client not to cache our HTML response (in our case it is also a JSON file which has a pricing config). As for the rest content type, we force the client to cache it for 1 year.</p><p>Finally we have also added a minor CI/CD, which we will share with you in the next article. But the main idea here is that as soon as the application is built and deployed, we automatically request all the public URLs that are available in the app. This will make sure that the site will work quick enough even for the first real client after we deploy its new version.</p><p>Hope this gives you some main ideas and overview about the mixing of Angular SSR, Apache Proxy and Cache and it will be useful for your projects too. Or maybe you will be smarter and choose a more easy way, e.g. by using Wordpress for your public pages :)</p><p><strong>TODO. </strong>We still need to remove some possibly redundant directives that are present in the VirtualHost file above. But before this, we need to perform a few additional tests. Thanks ahead for your comments and corrections!</p><p>P.S. In case you are interested in how such an Angular SSR app works and performs through Apache, you might want to visit a site here: <a href="https://quickmocker.com/">QuickMocker</a>. And in case you are interested in what is it: it is a simple cloud-based solution for creating API mocks (or API mocking) which should be useful for many developers that need to test their app, while they do not have required web services. Also it could be really useful for integration of webhooks from some 3-rd parties in order to debug incoming requests. Has lots of useful features like URL RegExp, shortcodes, easy drag &amp; drop prioritization of endpoints and so on. If you have any comments, please drop us a message through our <a href="https://quickmocker.com/#contact">contact form</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8fe2e4b3fff" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>