<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tony DeFusco</title>
    <description>The latest articles on DEV Community by Tony DeFusco (@tonedef71).</description>
    <link>https://dev.to/tonedef71</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F522947%2F4b8c560b-b365-4fa0-b4df-4b2f0f99a636.png</url>
      <title>DEV Community: Tony DeFusco</title>
      <link>https://dev.to/tonedef71</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tonedef71"/>
    <language>en</language>
    <item>
      <title>Everyday is an API day with Jotto 2020</title>
      <dc:creator>Tony DeFusco</dc:creator>
      <pubDate>Mon, 30 Nov 2020 04:57:34 +0000</pubDate>
      <link>https://dev.to/tonedef71/everyday-is-an-api-day-with-jotto-5eh8</link>
      <guid>https://dev.to/tonedef71/everyday-is-an-api-day-with-jotto-5eh8</guid>
      <description>&lt;p&gt;For my very first MuleSoft Hackathon, I decided to recreate a word puzzle game known as &lt;a href="https://en.wikipedia.org/wiki/Jotto" rel="noopener noreferrer"&gt;Jotto&lt;/a&gt;.  The game engine is an API implemented in Mule 4 using DataWeave 2 scripts along with some encryption from the Mule Crypto module. The source code for the game API has been uploaded to GitHub and can be found &lt;a href="https://github.com/tonedef71/jotto-2020-api" rel="noopener noreferrer"&gt;here&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;For the game's user interface, I created a simple web client using &lt;a href="http://enyojs.com/" rel="noopener noreferrer"&gt;EnyoJS&lt;/a&gt; v2.7.  The majority of my hours spent working on this hackathon were devoted to the web client (learning the basics of the EnyoJs JavaScript application framework and debugging my JavaScript code). The source code for the web client has been uploaded to GitHub and can be found &lt;a href="https://github.com/tonedef71/jotto-2020-web-client" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I created a free account with &lt;a href="https://fauna.com/" rel="noopener noreferrer"&gt;Fauna&lt;/a&gt; so that I could have an online document database at my disposal for persisting a small amount of game state data.  I used  FaunaDB's API to manage a running count of Jotto games played for each of the different word lengths.  Persisted running counts are leveraged to ensure that a fresh word gets served up with each new game.&lt;/p&gt;

&lt;p&gt;For the MuleSoft Hackathon, I created a free &lt;a href="https://anypoint.mulesoft.com/login/signup" rel="noopener noreferrer"&gt;30-day trial Anypoint Platform account&lt;/a&gt; to host the game's API along with the game's web client.  &lt;/p&gt;

&lt;p&gt;A demo of the &lt;strong&gt;Jotto 2020&lt;/strong&gt; game can be played online in your browser &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; &lt;a href="http://jotto2020.us-e2.cloudhub.io/ui/index.html" rel="noopener noreferrer"&gt;&lt;strong&gt;right here&lt;/strong&gt;&lt;/a&gt; &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs8.gifyu.com%2Fimages%2FJotto2020_demonstration.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs8.gifyu.com%2Fimages%2FJotto2020_demonstration.gif" alt="Jotto 2020 demo video"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;To Build the Mule Application Project:&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Clone the &lt;a href="https://github.com/tonedef71/jotto-2020-api" rel="noopener noreferrer"&gt;Jotto 2020 API project from GitHub&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;You may need to adjust the URLs of the two API endpoints.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In &lt;em&gt;src/main/resources/web/jotto-2020.js&lt;/em&gt; (around line 615) is where the endpoint URLs for the Mule APIs are configured.&lt;br&gt;&lt;br&gt;
The "url" field for "newGameWebService" and "newGuessWebService" must be set appropriately for the web client to function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    {
      kind: WebService,
      name: "newGameWebService",
...
      //url: "http://localhost:8081/api/game/jotto",
      url: "http://jotto2020.us-e2.cloudhub.io/api/game/jotto",
      method: "POST",
...
    },
    {
      kind: WebService,
      name: "newGuessWebService",
...
      //url: "http://localhost:8081/api/game/jotto/guess/",
      url: "http://jotto2020.us-e2.cloudhub.io/api/game/jotto/guess/",
      method: "PUT",
...
    },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Assuming the Mule application builds and deploys, you can access the web client in your browser with a URL that references the same host that is servicing the API.  For example, if you are running the application in the standalone Mule 4 server and you have the endpoint URLs set to localhost, then you would browse to &lt;strong&gt;&lt;a href="http://localhost:8081/ui/index.html" rel="noopener noreferrer"&gt;http://localhost:8081/ui/index.html&lt;/a&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;API Endpoints&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The Jotto 2020 API has two endpoints used to manage the game:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An API endpoint to request the game server to &lt;em&gt;start a new game&lt;/em&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;POST:/api/game/jotto?letters=&lt;em&gt;n&lt;/em&gt;&lt;/strong&gt; where &lt;em&gt;n&lt;/em&gt; for the &lt;code&gt;letters&lt;/code&gt; query parameter is an integer value between 2 and 12.&lt;/p&gt;

&lt;h4&gt;
  
  
  Sample JSON response body (a new game has started)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "stats": {
    "puzzleUuid": "46b602ec-cf04-4d39-9b88-18a41c1318c1",
    "puzzleIndex": 109,
    "puzzleLength": 8,
    "maximumTurns": 6,
    "gameOver": false,
    "turnsRemaining": 6,
    "victory": false
  },
  "turnsTaken": [

  ],
  "token": "ewogICJzdGF0cyI6IHsKICAgICJwdXp6bGVVdWlkIjogIjQ2YjYwMmVjLWNmMDQtNGQzOS05Yjg4LTE4YTQxYzEzMThjMSIsCiAgICAicHV6emxlSW5kZXgiOiAxMDksCiAgICAicHpbXVtVHVybnMiOiAyMCwKICAgICJnYW1lT3ZlciI6IGZhbHNlLAogICAgInR1cm5zUmVtYWluaW5nIjogMjAsCiAgICAiV6emxlTGVuZ3RoIjogOCwKICAgICJtYXhdmljdG9yeSI6IGZhbHNlCiAgfSwKICAidG9rZW4iOiBudWxsLAogICJ0dXJuc1Rha2VuIjogWwogICAgCiAgXQp9"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;An API endpoint to &lt;em&gt;submit a guess&lt;/em&gt; to the game server and receive feedback of the game's running state.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;PUT:/api/game/jotto/guess/{guess}&lt;/strong&gt; where &lt;code&gt;guess&lt;/code&gt; is a word of the proper length (between 2 and 12 letters depending on the length requested when the game was started).&lt;/p&gt;

&lt;p&gt;The PUT request must also include an HTTP header parameter named &lt;code&gt;x-session&lt;/code&gt; which contains the value of the &lt;code&gt;token&lt;/code&gt; field extracted from the most recent API response (the API will respond with an HTTP 400 status if the &lt;code&gt;x-session&lt;/code&gt; HTTP header parameter is omitted).  The &lt;code&gt;x-session&lt;/code&gt; HTTP parameter and the &lt;code&gt;token&lt;/code&gt; response body field together implement the mechanism used to maintain game state between client and server in a stateless manner.&lt;/p&gt;

&lt;h4&gt;
  
  
  Sample JSON response body (the final round of a winning game)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "stats": {
    "puzzleUuid": "5b449db2-1aeb-4962-b7e8-ac913f5d38e5",
    "puzzleIndex": 106,
    "puzzleLength": 8,
    "maximumTurns": 6,
    "gameOver": true,
    "turnsRemaining": 0,
    "victory": true,
    "puzzleWord": "document"
  },
  "turnsTaken": [
    {
      "guess": "hooligan",
      "result": ".*.....o"
    },
    {
      "guess": "tonality",
      "result": "o*o....."
    },
    {
      "guess": "national",
      "result": "o.o.o..."
    },
    {
      "guess": "vocation",
      "result": ".**.o..o"
    },
    {
      "guess": "lockment",
      "result": ".**.****"
    },
    {
      "guess": "document",
      "result": "********"
    }
  ],
  "token": "ewogICJzdGF0cyI6IHsKICAgICJwdXp6bGVVdWlkIjogIjViNDQ5ZGIyLTFhZWItNDk2Mi1iN2U4LWFjOTEzZjVkMzhlNSIsCiAgICsKICAgICAgImd1ZXNzIjogImhvb2xpZ2FuIiwKICAgICAgInJlc3VsdCI6ICIuKi4uLi4ubyIKICAgIH0sCiAgICB7CiAgICAgICJndWVzcyI6ICJub3Rpb25hbCIsCiAgICAgICJyZXN1bHQiOiAibypvLi4uLi4iCiAgICB9LAogICAgewogICAgICAiZ3Vlc3MiOiAidG9uYWxpdHkiLAogICAgICAicmVzdWx0IjogIm8qby4uLi4uIgogICAgfSwKICAgIHsKICAgICAgImd1ZXNzIjogIm5hdGlvbmFsIiwKICAgICAgInJlc3VsdCI6ICJvLm8uby4uLiIKICAgIH0sCiAgICB7CiAgICAgAicHV6emxlSW5kZXgiOiAxMDYsCiAgICAicHV6emxlTGVuZ3RoIjogOCwKICAgICJtYXhpbXVtVHVybnMiOiAyMCwKICAgICJnYW1lT3ZlciI6IHRydWUsCiAgICAidHVybnNSZW1haW5pbmciOiAxMywKICAgICJ2aWN0b3J5IjogdHJ1ZQogIH0sCiAgInRva2VuIjogbnVsbCwKICAidHVybnNUYWtlbiI6IFsKICAgIHICJndWVzcyI6ICJ2b2NhdGlvbiIsCiAgICAgICJyZXN1bHQiOiAiLioqLm8uLm8iCiAgICB9LAogICAgewogICAgICAiZ3Vlc3MiOiAibG9ja21lbnQiLAogICAgICAicmVzdWx0IjogIi4qKi4qKioqIgogICAgfSwKICAgIHsKICAgICAgImd1ZXNzIjogImRvY3VtZW50IiwKICAgICAgInJlc3VsdCI6ICIqKioqKioqKiIKICAgIH0KICBdCn0="
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;puzzleWord&lt;/code&gt; field is only included in the response body when the &lt;code&gt;gameOver&lt;/code&gt; field has a value of &lt;code&gt;true&lt;/code&gt;. In the values of the "result" fields, the &lt;code&gt;.&lt;/code&gt; denotes a non-matching letter, the &lt;code&gt;o&lt;/code&gt; denotes a matching letter in the incorrect position, and the &lt;code&gt;*&lt;/code&gt; denotes a matching letter in the correct position.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;How to Play Jotto 2020&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Jotto 2020 is a word puzzle game. The game server will select a secret English word between 2 and 12 letters; you get to select the word length.&lt;/p&gt;

&lt;p&gt;The object of the game is to guess that secret word. Each guess you make will be answered by a report of the letters (or "jots") in the guess word that match or occur in the secret word. &lt;/p&gt;

&lt;p&gt;You will also be told how many of the letters are in the correct position in the secret word. &lt;/p&gt;

&lt;p&gt;Through a process of elimination, you should be able to deduce the correct letters using logic.&lt;/p&gt;

&lt;p&gt;The number of allowed guesses to solve the secret word varies based on the length of the secret word.  The minimum is five guesses.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Start by selecting the number of letters for the mystery word via the number picker button on the top-left.  You can select a mystery word as short as two letters, or as long as twelve letters.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Type your test or guess word; it must be the same number of letters as the mystery word.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After you have entered your guess word, click the "-&amp;gt;" button on the on-screen keypad or press the "Enter" key on your computer's keyboard to submit your guess to the game server.  Click the "&amp;lt;-" key on the keypad or press the backspace on your computer keyboard to erase the last entered letter of your guess.  Click the "!" key on the keypad or press the "Esc" key on your computer keyboard to erase all of the letters of your guess.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The game server will report which letters of your guess occur in the secret word and whether or not any of those letters are in the correct position.&lt;br&gt;
Yellow letters will be displayed for those letters that are in the secret word but are in the wrong position.&lt;br&gt;
Green letters will only be displayed for those letters that are both in the secret word and in the correct position.&lt;br&gt;
Red letters will be displayed for letters that do not exist in the secret word or for any extra copies of letters that have already been displayed as yellow or green letters.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;If the secret 5-letter word is "radar"...

  ... and you guessed "arrow", 
  then the game server will report a result displayed as
  three yellow letters and two red letters.

  ... and you guessed "razor", 
  then the game server will report a result displayed as 
  three green letters and two red letters.

  ... and you guessed "raarr", 
  then the game server will report a result displayed as 
  four green letters and one red letter; the extra 'R' is 
  not in the secret word.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Continue submitting guesses to the game server until you correctly solve the mystery word or you run out of allowed guess attempts.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Parting Thoughts&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The web client consumed way too much of the free time I budgeted for this hackathon, and as a result, this whole project was badly rushed to meet the submission deadline.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Some unfinished business remains:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Remove trace log statements from web client code.&lt;/li&gt;
&lt;li&gt;Add more tool tips and prepare better help instructions in the web client.&lt;/li&gt;
&lt;li&gt;Employ better EnyoJS and JavaScript coding best practices by refactoring the web client source code to create reusable components.&lt;/li&gt;
&lt;li&gt;Enable HTTPS by requesting a proper TLS certificate for the host server's domain.&lt;/li&gt;
&lt;li&gt;Use the FaunaDB to persist more data for the game server.&lt;/li&gt;
&lt;li&gt;Do more play-testing.  Are the minimum number of guesses enforced by the game server suitable for the different word lengths?&lt;/li&gt;
&lt;li&gt;Remedy the "uglify" compatibility bug in the node.js build script that is preventing a production build of the EnyoJS project.&lt;/li&gt;
&lt;li&gt;Figure out how to make the "x-session" HTTP header response parameter accessible to the web client.  Currently, the "x-session" HTTP header parameter does not show up after invoking the &lt;em&gt;getAllResponseHeaders()&lt;/em&gt; function in the browser's &lt;em&gt;XMLHttpRequest response&lt;/em&gt; object.  This is why the "token" field had to be included in the API's response body.&lt;/li&gt;
&lt;li&gt;Move the RAML out of the Mule 4 project and into Exchange, and then manage it with API Manager.&lt;/li&gt;
&lt;li&gt;Host the web client separately from the API? A proper web server would be best.&lt;/li&gt;
&lt;li&gt;Secure the API endpoints.&lt;/li&gt;
&lt;li&gt;I like using the different colors to provide visual feedback for qualifying a guess, but I do realize that an alternate feedback mechanism would be needed to accommodate players with color blindness.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Game enhancements:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add features to the game server such as player game history management; the game client could then be enhanced to display all time best scores and personal best scores, etc.&lt;/li&gt;
&lt;li&gt;Improve the game client and then convert it into a mobile application and/or standalone executable for PC or Mac.&lt;/li&gt;
&lt;/ol&gt;




</description>
      <category>mulesofthackathon</category>
      <category>jotto2020</category>
      <category>wordle</category>
    </item>
  </channel>
</rss>
