<?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 Enzo Haussecker on Medium]]></title>
        <description><![CDATA[Stories by Enzo Haussecker on Medium]]></description>
        <link>https://medium.com/@ehaussecker?source=rss-6e430f41a931------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*Z6Q798ITN01JBlKyYYk3ig.jpeg</url>
            <title>Stories by Enzo Haussecker on Medium</title>
            <link>https://medium.com/@ehaussecker?source=rss-6e430f41a931------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 10:03:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ehaussecker/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[How to Compose Microservices on the Internet Computer]]></title>
            <link>https://medium.com/@ehaussecker/how-to-compose-microservices-on-the-internet-computer-232ff9eff0e6?source=rss-6e430f41a931------2</link>
            <guid isPermaLink="false">https://medium.com/p/232ff9eff0e6</guid>
            <category><![CDATA[dfinity]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[motoko]]></category>
            <dc:creator><![CDATA[Enzo Haussecker]]></dc:creator>
            <pubDate>Fri, 07 Aug 2020 15:57:25 GMT</pubDate>
            <atom:updated>2020-08-07T17:39:17.637Z</atom:updated>
            <content:encoded><![CDATA[<h4>Understanding the async/await syntax in Motoko</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FtvUkzrIZFBU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DtvUkzrIZFBU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FtvUkzrIZFBU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e067f4f7a26ba86311862da28f9aec93/href">https://medium.com/media/e067f4f7a26ba86311862da28f9aec93/href</a></iframe><h4>Introduction</h4><p>Microservice composition on the <a href="https://dfinity.org/">Internet Computer</a> occurs when two or more microservices communicate with one another to achieve a common goal. <a href="https://sdk.dfinity.org/docs/language-guide/motoko.html">Motoko</a>, a popular programming language for developing microservices on the Internet Computer, provides first class support for microservice composition via its <a href="https://sdk.dfinity.org/docs/language-guide/actors-async.html">async/await syntax</a>. The correct usage for that syntax depends on whether the microservices communicating exist within the same project or across separate projects. This article helps clarify any ambiguity as it relates to the syntax.</p><h4>Working Within the Same Project</h4><p>If the microservice you want to communicate with exists in your current project, then you can simply import it and invoke any of its public methods.</p><p>Consider this example:</p><pre>$ mkdir project-1<br>$ cd project-1</pre><p>Create a file called dfx.json with the following contents.</p><pre>{<br>  &quot;canisters&quot;: {<br>    &quot;A&quot;: {<br>      &quot;main&quot;: &quot;A.mo&quot;<br>    },<br>    &quot;B&quot;: {<br>      &quot;main&quot;: &quot;B.mo&quot;<br>    }<br>  }<br>}</pre><p>Create a file called A.mo with the following contents.</p><pre>actor A {<br>  public func hello() : async Text {<br>    return &quot;Hello&quot;;<br>  };<br>};</pre><p>Create a file called B.mo with the following contents.</p><pre>import A &quot;canister:A&quot;;</pre><pre>actor B {<br>  public func hello_world() : async Text {<br>    let hello = await A.hello();<br>    return hello # &quot; World&quot;;<br>  };<br>};</pre><p>Run the following commands.</p><pre>$ dfx canister create --all<br>$ dfx build<br>$ dfx canister install --all<br>$ dfx canister call B hello_world<br>(&quot;Hello World&quot;)</pre><h4>Working Across Separate Projects</h4><p>If the microservice you want to communicate with does not exist in your current project, then you must define it and any public methods you want to invoke.</p><p>Consider this example:</p><pre>$ mkdir project-2<br>$ cd project-2</pre><p>Create a file called dfx.json with the following contents.</p><pre>{<br>  &quot;canisters&quot;: {<br>    &quot;C&quot;: {<br>      &quot;main&quot;: &quot;C.mo&quot;<br>    }<br>  }<br>}</pre><p>Create a file called C.mo with the following contents.</p><pre>let A : actor {<br>  hello() : async Text;<br>} = actor &quot;ic:0100000000000000000000000000000000012D&quot;;</pre><pre>actor C {<br>  public func hello_world() : async Text {<br>    let hello = await A.hello();<br>    return hello # &quot; World&quot;;<br>  };<br>};</pre><p>Note that identifier on line three should match whatever the network assigned to microservice A.</p><p>Run the following commands.</p><pre>$ dfx canister create --all<br>$ dfx build<br>$ dfx canister install --all<br>$ dfx canister call C hello_world<br>(&quot;Hello World&quot;)</pre><h4>Conclusion</h4><p>The files B.mo and C.mo differ only in how they reference microservice A. It’s easy to confuse them, so hopefully you found some clarity in this article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=232ff9eff0e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My First Microservice on DFINITY]]></title>
            <link>https://medium.com/@ehaussecker/my-first-microservice-on-dfinity-3ac5c142865b?source=rss-6e430f41a931------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ac5c142865b</guid>
            <dc:creator><![CDATA[Enzo Haussecker]]></dc:creator>
            <pubDate>Mon, 02 Mar 2020 08:11:27 GMT</pubDate>
            <atom:updated>2020-07-06T23:12:38.174Z</atom:updated>
            <content:encoded><![CDATA[<h3>My First Microservice on the Internet Computer</h3><h4>A QR Code Generator in Pure Motoko</h4><h4>Introduction</h4><p>The <a href="https://dfinity.org/">Internet Computer</a> is conceived as a secure network protocol that allows untrusted data centers to host trusted microservices on behalf of anyone with <a href="https://info.binance.com/en/currencies/dfinity">internet compute tokens</a>. I set out to build my first microservice on the Internet Computer and thought to share my experiences, which were definitely very positive!</p><h4>What to build?</h4><p>I wanted to build something simple, but not trivial. Hence, a microservice to echo hello world or calculate the factorial of a given number would not suffice. It needed to be something I could actually use and integrate into my existing stack. After a quick head scratch, I settled on a QR code generator, which I needed to display cryptocurrency wallet addresses.</p><h4><strong>How to build it?</strong></h4><p>Microservices on the Internet Computer run in a <a href="https://webassembly.org/">WebAssembly</a> virtual machine, so to build a microservice, one simply needs to develop a program that compiles down to WebAssembly. There are several existing libraries to generate QR codes, such those in C and Rust, which compile down to WebAssembly. I easily could have used one of those, but being the adventurous developer that I am, I decided to develop my own in <a href="https://sdk.dfinity.org/docs/language-guide/motoko.html">Motoko</a>.</p><h4>What is Motoko?</h4><p>Motoko is a high-level language designed by the authors of the WebAssembly specification. It is syntactically similar to Swift and unique in that it provides first class support for microservice composition on the Internet Computer.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FWVeovvm3znE%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DWVeovvm3znE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FWVeovvm3znE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c422cbb00625d12e9359d5898c67077/href">https://medium.com/media/0c422cbb00625d12e9359d5898c67077/href</a></iframe><p>To obtain the latest version of the Motoko compiler, one simply needs to download and install the Internet Computer SDK.</p><pre>$ wget https://sdk.dfinity.org/install.sh<br>$ yes Y | sh install.sh</pre><h4>Preliminaries</h4><p>Before defining an interface for my microservice in Motoko, it helps to review the QR code <a href="https://www.iso.org/standard/62021.html">specification</a> to understand the components that make up these ubiquitous matrix barcodes. The symbology breaks down like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pNwV4qPor5Luh3rv3d4UpA.png" /></figure><p>The relevant parameters needed to produce these components include a version number from 1 to 40, an error correction level of L, M, Q, or H, representing data loss tolerances of 7%, 15%, 25%, and 30%, respectively, and an encoding scheme, which could be numeric, alphanumeric, eight-bit, or Kanji.</p><h4><strong>Interface Definition</strong></h4><p>Translating the above into Motoko type definitions gives us the following:</p><pre>public type Version = { #Version : Nat };</pre><pre>public type ErrorCorrection = { #L; #M; #Q; #H };</pre><pre>public type Mode = { #Alphanumeric; #EightBit; #Kanji; #Numeric };</pre><pre>public type Matrix = { #Matrix : [[Bool]] };</pre><p>Using these type definitions, we can define a high-level function in Motoko to generate QR codes.</p><pre>/**<br> * Encodes the input text according to the QR code specification or<br> * returns null if the input text is invalid for the given mode.<br> */<br>public func encode(<br>  version : Version,       // Version number. <br>  level : ErrorCorrection, // Error correction level.<br>  mode : Mode,             // Encoding scheme.<br>  input : Text             // Input text.<br>) : async ?Matrix { .. };</pre><p>Wrapping the above in a Motoko actor declaration defines the interface.</p><h4>Implementation</h4><p>The implementation is available on <a href="https://github.com/enzoh/qr">GitHub</a>. It worked out to just over 2,000 lines of code and required over a dozen supporting modules. The best way to browse the code is by cloning the repository and opening it in <a href="https://code.visualstudio.com/">Visual Studio</a>, for which there exists a Motoko syntax highlighting <a href="https://marketplace.visualstudio.com/publishers/BlockInsight">extension</a>.</p><pre>$ git clone https://github.com/enzoh/motoko-qr<br>$ code qr</pre><p>The implementation relied heavily on the Motoko <a href="https://sdk.dfinity.org/docs/language-guide/stdlib/stdlib-intro.html">standard library</a>, which I found to be relatively mature and featureful. The APIs provided there seem heavily influenced by Rust and Standard ML, and being a user of those languages, I rarely needed to consult any documentation. This was especially fortunate because the documentation website is still under development. Nevertheless, the most up-to-date details could always be found by opening the standard library directly in Visual Studio.</p><pre>$ code $HOME/.cache/dfinity/versions/$DFX_VERSION/base</pre><h4>Demo</h4><p>Start a local internet compute replica.</p><pre>$ dfx start</pre><p>Execute the following commands in another tab.</p><pre>$ dfx build<br>$ dfx canister install --all<br>$ dfx canister call demo encode \<br>$   &#39;(variant{Version=2}, variant{M}, variant{Alphanumeric}, &quot;HTTPS://SDK.DFINITY.ORG&quot;)&#39; \<br>$   | sed &#39;s/[(&quot;)]//g&#39; \<br>$   | sed &#39;s/#/█/g&#39;</pre><p>Observe the following result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/371/1*IEAMm7SgOnrrBxwN5unRHw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ac5c142865b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>