<?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:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[RandomAPI Developer Blog]]></title><description><![CDATA[Official developer blog for RandomUser and RandomAPI.]]></description><link>https://blog.randomapi.com/</link><generator>Ghost 0.10</generator><lastBuildDate>Tue, 02 Aug 2022 21:54:06 GMT</lastBuildDate><atom:link href="https://blog.randomapi.com/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Offline RandomAPI]]></title><description><![CDATA[<h3 id="whatisofflinerandomapi">What is Offline RandomAPI?</h3>

<p>Offline RandomAPI (OfflineAPI) is an <a href="https://www.npmjs.com/package/randomapi">NPM module</a> that you can install on your own machine to generate your APIs locally. Your own instance or instances of the RandomAPI Generator run locally on your computer (on port 61337 by default) and can be accessed in the same</p>]]></description><link>https://blog.randomapi.com/offline-randomapi/</link><guid isPermaLink="false">afd256e2-eb92-4e77-8b3e-256a812666b0</guid><category><![CDATA[randomapi]]></category><category><![CDATA[offlineapi]]></category><dc:creator><![CDATA[Keith Armstrong]]></dc:creator><pubDate>Fri, 16 Sep 2016 21:42:00 GMT</pubDate><content:encoded><![CDATA[<h3 id="whatisofflinerandomapi">What is Offline RandomAPI?</h3>

<p>Offline RandomAPI (OfflineAPI) is an <a href="https://www.npmjs.com/package/randomapi">NPM module</a> that you can install on your own machine to generate your APIs locally. Your own instance or instances of the RandomAPI Generator run locally on your computer (on port 61337 by default) and can be accessed in the same way as you access RandomAPI currently.</p>

<h3 id="why">Why?</h3>

<p>If latency, uptime, and speed are big concerns, OfflineAPI is perfect for you! You also won't need to compete with other users in your tier for resources on the RandomAPI servers during times of heavy load, and if you are traveling or somewhere without internet and need your random data, that won't be an issue either!</p>

<h3 id="sowhatsthecatch">So what's the catch?</h3>

<p>OfflineAPI is currently only available for premium accounts. In the future, this feature may expand to standard accounts, but for now, it's exclusive to premium users.</p>

<h3 id="alrightyouvegotmesoldhowdoiuseit">Alright you've got me sold, how do I use it?</h3>

<p>Since RandomAPI runs on Node.js, the Generator naturally runs on Node.js as well. Make sure that you have Node and NPM installed on your machine.</p>

<p>Next, install the OfflineAPI module globally by running <br>
<code>npm install randomapi -g</code></p>

<p>Since OfflineAPI is a CLI script, we highly recommend installing it globally so you can access it from your terminal with <code>randomapi</code>.</p>

<p>After OfflineAPI finishes installing, it'll automatically launch the RandomAPI Generator in the background as a daemon on port 61337. You can run <code>randomapi</code> now if you would like to see the available commands.</p>

<blockquote>
  <p>At the time of writing this, there are currently some issues with getting the generator to run in the background on Windows. It currently opens up a new console window that you'll have to keep running in order for the generator to run. For now, you'll have to just minimize the window until we have an update for Windows. OS X and Linux users should be unaffected.</p>
</blockquote>

<p>Next, we have to create an authToken on RandomAPI in order to authenticate your account with the server to sync your APIs, Lists, and Snippets.</p>

<p>Login to your RandomAPI account, go to settings, and then click on Offline RandomAPI. Or, you can click <a href="http://beta.randomapi.com/settings/offline#active">here</a> if you want to be lazy :)</p>

<p>Your screen should look like this <br>
<img src="https://blog.randomapi.com/content/images/2016/09/Screen-Shot-2016-09-16-at-5.06.03-PM.png" style="width: 850px;"></p>

<p>Click on create new token and give your token a name and give your account password to authenticate yourself.</p>

<p><img src="https://blog.randomapi.com/content/images/2016/09/Screen-Shot-2016-09-16-at-5.08.26-PM.png" style="width: 850px;"></p>

<p>You will receive an authToken after you submit the form. Make sure that you copy this token now, you won't be able to see it again after you leave the page.</p>

<p><img src="https://blog.randomapi.com/content/images/2016/09/Screen-Shot-2016-09-16-at-5.08.30-PM.png" style="width: 850px;"></p>

<p>Next, go back to OfflineAPI and type <code>randomapi login</code>. <br>
<img src="https://blog.randomapi.com/content/images/2016/09/Screen-Shot-2016-09-16-at-5.11.36-PM.png" style="width: 500px;"></p>

<p>Give your username and the authToken we just generated to link your offline account with RandomAPI.  </p>

<blockquote>
  <p>authTokens are linked to your account and can not be used with other accounts. They are also one time use.</p>
</blockquote>

<p>If all goes well, you should get this screen: <br>
<img src="https://blog.randomapi.com/content/images/2016/09/Screen-Shot-2016-09-16-at-5.15.22-PM.png" style="width: 500px;"></p>

<blockquote>
  <p>If you are on Windows and the prompt doesn't reappear after you login, press CTRL-C to exit</p>
</blockquote>

<p>Congratulations, your account and computer are now linked with your RandomAPI account!</p>

<p>Next, we need to sync with the RandomAPI server. Type <code>randomapi sync</code> to run the sync operation. After the operation completes, the RandomAPI server will automatically restart to load in the latest changes. <br>
<img src="https://blog.randomapi.com/content/images/2016/09/Screen-Shot-2016-09-16-at-5.18.37-PM.png" style="width: 500px;"> <br>
Type <code>randomapi ls</code> to view the APIs that are currently available locally. <br>
<img src="https://blog.randomapi.com/content/images/2016/09/Screen-Shot-2016-09-16-at-5.20.56-PM.png" style="width: 500px;"></p>

<p>Let's generate the Geocaching API demo that we made in this <a href="http://blog.randomapi.com/geocaching-api-demo/">blog post</a>.</p>

<p><code>randomapi gen 3</code></p>

<blockquote>
  <p>Notice how I ran <code>3</code> instead of typing out <code>pgfznwxq</code>. The CLI references the ordering of the APIs when you run the <code>ls</code> command for convenience.</p>
</blockquote>

<p><img src="https://blog.randomapi.com/content/images/2016/09/Screen-Shot-2016-09-16-at-5.24.50-PM.png" style="width: 500px;"></p>

<p>Now how do you pass parameters like on the web version of RandomAPI? Just pass the parameters as a comma delimited list as the next argument.</p>

<p><code>randomapi gen 3 results=2,fmt=csv,seed=a</code>
<img src="https://blog.randomapi.com/content/images/2016/09/Screen-Shot-2016-09-16-at-5.26.34-PM.png" style="width: 600px;"></p>

<p>If you want to use the generator in the browser, you are free to do that as well!  </p>

<blockquote>
  <p>Make sure that you use &amp; in your parameters and the actual ref id in the browser</p>
</blockquote>

<p><img src="https://blog.randomapi.com/content/images/2016/09/Screen-Shot-2016-09-16-at-5.30.02-PM.png" style="width: 600px;"></p>

<p>You can also access the same URL in any http library like curl or httplib in Python! <br>
<img src="https://blog.randomapi.com/content/images/2016/09/Screen-Shot-2016-09-16-at-5.30.55-PM.png" style="width: 600px;"></p>]]></content:encoded></item><item><title><![CDATA[What is a Snippet?]]></title><description><![CDATA[<p>A snippet is a user-defined piece of code that can be included in your API. If you've made a function that you think could be helpful to others, you can share your snippet by publishing it for others to search for! Think of it like node modules for NPM.</p>

<p>Snippets</p>]]></description><link>https://blog.randomapi.com/what-is-a-snippet/</link><guid isPermaLink="false">88b8b718-e7a3-4aa6-916f-14855f385fa7</guid><category><![CDATA[randomapi]]></category><category><![CDATA[definition]]></category><dc:creator><![CDATA[Keith Armstrong]]></dc:creator><pubDate>Wed, 14 Sep 2016 21:10:09 GMT</pubDate><content:encoded><![CDATA[<p>A snippet is a user-defined piece of code that can be included in your API. If you've made a function that you think could be helpful to others, you can share your snippet by publishing it for others to search for! Think of it like node modules for NPM.</p>

<p>Snippets are also useful for organizing your code/APIs. If you use a piece of code often in many of your APIs, you could make a private snippet and then reference the snippet in your APIs to save space and make your code more readable.</p>

<p>From this  </p>

<pre><code class="language-javascript">api.phone = phoneNum();

function phoneNum(format) {  
  format = format || "(xxx) xxx-xxxx";
  return String(format).split('').map(digit =&gt; {
    return digit === 'x' ? random.numeric(0, 9) : digit;
  }).join('');
}
</code></pre>

<p>To this  </p>

<pre><code class="language-javascript">const phoneNum = require('~phoneNum');

api.phone = phoneNum();  
</code></pre>

<p>To make the above snippet, I made a new snippet called "phoneNum" and assigned my function to the variable <code>snippet</code>. Snippets are coded in basically the same way as a normal API except for these key differences:</p>

<ul>
<li>Objects are attached to the snippet object instead of the api object.</li>
<li>Only Global Snippets can be used in your snippet. You can't require other snippets from your snippet.</li>
<li>Snippet names must be unique in regards to your account (you can't have two snippets named "phonenum" for example).</li>
<li>Only inline lists can be used in your API.</li>
</ul>

<pre><code class="language-javascript">snippet = function(format) {  
  format = format || "(xxx) xxx-xxxx";
  return String(format).split('').map(digit =&gt; {
    return digit === 'x' ? random.numeric(0, 9) : digit;
  }).join('');
};
</code></pre>

<p>In the phone number example above, I attached my function directly to the snippet object kind of like what we did at the end of the <a href="http://blog.randomapi.com/what-is-an-api/">What is an API</a> blog post. But, you also have the option to attach multiple functions to a snippet as different properties. You can then access those snippet functions using their property names.</p>

<blockquote>
  <p>mysnippet</p>
</blockquote>

<pre><code class="language-javascript">snippet.a = function() {  
    return "a";
};

snippet.b = function() {  
    return "b";
};

snippet.randomHexLetter = function() {  
    return list(['a', 'b', 'c', 'd', 'e', 'f']);
};
</code></pre>

<p>This snippet is pretty useless, but you can imagine the power that snippets have when used in conjunction with other snippets in your API.</p>

<p>To access the snippet functions above, you'd use the <code>require</code> function.</p>

<pre><code class="language-javascript">const mysnippet = require('~mysnippet');

api.a = mysnippet.a();  
api.b = mysnippet.b();  
api.hex = mysnippet.randomHexLetter();  
</code></pre>

<pre><code class="language-json">{
  "a": "a",
  "b": "b",
  "hex": "d"
}
</code></pre>

<p>You can also access snippets directly from the require function if you only need to use it once.  </p>

<pre><code class="language-javascript">api.a = require('~mysnippet').a();  
</code></pre>]]></content:encoded></item><item><title><![CDATA[Geocaching API Demo]]></title><description><![CDATA[<p>Today, we're going to make an example API that involves geocaching. Basically, we are going to make a fake Geocache generator that would ease the development of a geocaching website with fake data. This tutorial will go through the entire process of creating an API from beginning to end. If</p>]]></description><link>https://blog.randomapi.com/geocaching-api-demo/</link><guid isPermaLink="false">f5495110-9ee6-4028-a623-0bab24c51183</guid><category><![CDATA[randomapi]]></category><category><![CDATA[tutorial]]></category><dc:creator><![CDATA[Keith Armstrong]]></dc:creator><pubDate>Wed, 14 Sep 2016 19:07:38 GMT</pubDate><content:encoded><![CDATA[<p>Today, we're going to make an example API that involves geocaching. Basically, we are going to make a fake Geocache generator that would ease the development of a geocaching website with fake data. This tutorial will go through the entire process of creating an API from beginning to end. If you have any questions or feedback, please leave a comment below. Let's get started! :)</p>

<p><a href="http://beta.randomapi.com/api/3141b5683af0edf576dabdb50ef1ff64?fmt=prettyraw&amp;sole">Test out the final result of this demo API</a></p>

<hr>

<p>First, let's create a new API. To do this, click on "New API" from the side navbar, give your API a name, and then click "Add new API". This'll take you to the API editor.</p>

<p><img src="https://blog.randomapi.com/content/images/2016/09/Screen-Shot-2016-09-14-at-2.08.21-PM.png" style="width: 1000px;"></p>

<p>The API editor is split into two parts: a code editor on the left and a live preview on the right. The live preview will automatically execute your API code and show the results of your API code whenever it detects a change. You can also click Test API if you want to manually generate a new result.</p>

<p>After looking at some geocaching websites, it looks like these are some of the most common properties that a geocaching website would need.</p>

<ul>
<li>Name of the spot</li>
<li>Creator's username</li>
<li>Rating</li>
<li>Favorites</li>
<li>Number of visits</li>
<li>Difficulty</li>
<li>Terrain</li>
<li>Size</li>
<li>Date created</li>
<li>Date updated</li>
<li>Coordinates</li>
</ul>

<p>For the Geocache name, we are going to generate a very basic name consisting of adjectives and nouns.</p>

<pre><code class="language-javascript">api.name = trailname();

function trailname() {  
    let trails     = ["trail", "path", "route", "stream", "walkway", "beaten path", "footpath"]
    let adjectives = ["dusty", "old", "scenic", "historic", "shady", "sunny"];
    let colors     = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"];

    let combos = [
        [colors, trails],
        [adjectives, trails],
        [colors, adjectives, trails]
    ];

    let trailname = "";
    list(combos).forEach(part =&gt; trailname += " " + capitalize(list(part)));
    return trailname.trim();

    function capitalize(str) {
        return str.charAt(0).toUpperCase() + str.slice(1);
    }
}
</code></pre>

<pre><code class="language-json">{
  "name": "Violet Dusty Trail"
}
</code></pre>

<p>So now we have a name, but that trail function generator is kind of long and looks messy in our API. We are going to move the trailname function to a snippet since we may use it later on in other APIs and it'll clean up our code a bit. You can read more about implementing snippets <a href="http://blog.randomapi.com/what-is-a-snippet/">here</a>.</p>

<p>Here's what our API looks like now with our new trailname snippet.  </p>

<pre><code class="language-javascript">const trailname = require('~trailname');  
api.name        = trailname();  
</code></pre>

<p>Next, we are going to generate the geocache creator's username. We are to use the Faker.js global snippet for this field as well as for generating the coordinates for our geocache.</p>

<pre><code class="language-javascript">...
const faker     = require('faker'); // Faker.js library  
api.username    = faker.internet.userName();  
...
</code></pre>

<pre><code class="language-json">{
  "username": "Dewayne75"
}
</code></pre>

<p>Let's knock a few more properties out of the way with the <code>random.numeric</code> and <code>list</code> function. Rating, favorites, number of visits, difficulty, and terrain will all take numeric values for star ratings and pure numbers for favorites and number of visits. We will also try and make the values more realistic by basing values like favorites and visits off of previously calculated values.</p>

<pre><code class="language-javascript">...
api.rating     = random.numeric(0, 50) / 10;  
api.favorites  = Math.ceil(api.rating * random.numeric(1, 15));  
api.visits     = api.favorites * random.numeric(1, 15)  
api.difficulty = random.numeric(1, 5);  
api.terrain    = random.numeric(1, 5);  
api.size       = list(['mini', 'small', 'medium', 'big', 'large']);  
...
</code></pre>

<pre><code class="language-json">{
  "rating": 2.9,
  "favorites": 41,
  "visits": 369,
  "difficulty": 2,
  "terrain": 4,
  "size": "large"
}
</code></pre>

<p>For date created and date updated, we'll take advantage of the moment library to provide readable formatting.</p>

<pre><code class="language-javascript">...
const moment = require('moment');

// Created 30 - 900 days ago
let created = timestamp() - 86400 * random.numeric(30, 900);

// Moment accepts timestamps in milliseconds
api.created = moment(created * 1000).format('LL');

// Updated date will be before the present but after the creation date
let updated = timestamp() - random.numeric(0, timestamp() - created);  
api.updated = moment(updated * 1000).format('LL');  
...
</code></pre>

<pre><code class="language-json">{
  "created": "July 25, 2015",
  "updated": "March 26, 2016"
}
</code></pre>

<p>And finally, let's use the Faker.js library again to generate a random set of coordinates for the geocache.</p>

<pre><code class="language-javascript">api.coords = `${faker.address.latitude()} ${faker.address.longitude()}`;  
</code></pre>

<pre><code class="language-json">{
    "coords": "40.7013 15.9303"
}
</code></pre>

<hr>

<p>And we are finished! Here is the final API code (without the snippet so you can copy and paste directly) and an example of the results that it generated.</p>

<p><a href="http://beta.randomapi.com/api/3141b5683af0edf576dabdb50ef1ff64?fmt=prettyraw&amp;sole">Call the API directly yourself</a></p>

<pre><code class="language-javascript">const faker  = require('faker'); // Faker.js library  
const moment = require('moment');

api.name       = trailname();  
api.username   = faker.internet.userName();  
api.rating     = random.numeric(0, 50) / 10;  
api.favorites  = Math.ceil(api.rating * random.numeric(1, 15));  
api.visits     = api.favorites * random.numeric(1, 15)  
api.difficulty = random.numeric(1, 5);  
api.terrain    = random.numeric(1, 5);  
api.size       = list(['mini', 'small', 'medium', 'big', 'large']);

// Created 30 - 900 days ago
let created = timestamp() - 86400 * random.numeric(30, 900);

// Moment accepts timestamps in milliseconds
api.created = moment(created * 1000).format('LL');

// Updated date will be before the present but after the creation date
let updated = timestamp() - random.numeric(0, timestamp() - created);  
api.updated = moment(updated * 1000).format('LL');

api.coords = `${faker.address.latitude()} ${faker.address.longitude()}`;

// Snippet code
function trailname() {  
    let trails     = ["trail", "path", "route", "stream", "walkway", "beaten path", "footpath"]
    let adjectives = ["dusty", "old", "scenic", "historic", "shady", "sunny"];
    let colors     = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"];

    let combos = [
        [colors, trails],
        [adjectives, trails],
        [colors, adjectives, trails]
    ];

    let trailName = "";
    list(combos).forEach(part =&gt; trailName += " " + capitalize(list(part)));

    return trailName.trim();

    function capitalize(str) {
        return str.charAt(0).toUpperCase() + str.slice(1);
    }
}
</code></pre>

<pre><code class="language-json">{
  "name": "Indigo Dusty Path",
  "username": "Henry_Schaden",
  "rating": 1.8,
  "favorites": 15,
  "visits": 45,
  "difficulty": 4,
  "terrain": 2,
  "size": "mini",
  "created": "September 11, 2015",
  "updated": "November 15, 2015",
  "coords": "38.3802 -23.2441"
}
</code></pre>]]></content:encoded></item><item><title><![CDATA[Advanced uses for the getVar function]]></title><description><![CDATA[<p>You've seen how the getVar function can be used to access parameters in your query URI, but the getVar function can also be used to access a few internal RandomAPI features. If you'd like a refresher on the getVar function, take a look <a href="http://blog.randomapi.com/what-is-the-getvar-function/">here</a>.</p>

<p>The getVar function can access variables</p>]]></description><link>https://blog.randomapi.com/advanced-uses-for-the-getvar-function/</link><guid isPermaLink="false">7088c0b0-c587-4959-b991-04f3c8651f49</guid><category><![CDATA[randomapi]]></category><category><![CDATA[definition]]></category><dc:creator><![CDATA[Keith Armstrong]]></dc:creator><pubDate>Mon, 12 Sep 2016 22:34:26 GMT</pubDate><content:encoded><![CDATA[<p>You've seen how the getVar function can be used to access parameters in your query URI, but the getVar function can also be used to access a few internal RandomAPI features. If you'd like a refresher on the getVar function, take a look <a href="http://blog.randomapi.com/what-is-the-getvar-function/">here</a>.</p>

<p>The getVar function can access variables such as fmt, key, ref, etc. as well if you need to determine the format your API was requested in, etc.</p>

<p>You can also access some internal RandomAPI Generator variables such as <code>numericSeed</code> which is the internal seed that the generator is using for the current job it is generating. This could be especially useful if you are using a custom snippet or global snippet that has a seeding property you'd like to set (which we recommend so that the generator's seed and snippet's seed match each other and respect any custom seed values you might provide in your URI). <br>
Or if you need a number on the [0,1) real interval, you can use the special <code>prng()</code> function that will return a number directly from the Mersenne Twister module that the generator is using.  </p>

<pre><code class="language-javascript">api.seed    = getVar('seed');  
api.numSeed = getVar('numericSeed');  
api.format  = getVar('fmt');  
api.key     = getVar('key');  
api.ref     = getVar('ref');  
api.prng    = prng();  
</code></pre>

<pre><code class="language-json">{
  "seed": "7583c1fdce1943f4",
  "numericSeed": 4200665598,
  "format": "pretty",
  "key": "ABCD-1234-EFGH-5678",
  "ref": "1234abcd",
  "prng": 0.9772644529584795
}
</code></pre>]]></content:encoded></item><item><title><![CDATA[What is the getVar function?]]></title><description><![CDATA[<p>The getVar function fetches the GET variables from an API query. This gives your API the ability to receive some input data that you could configure to change the output.</p>

<p>Let's make a simple math API for example. In this example, we are basically generating 2 numbers and then performing</p>]]></description><link>https://blog.randomapi.com/what-is-the-getvar-function/</link><guid isPermaLink="false">777de265-d318-45a9-98d2-974b8df66d89</guid><category><![CDATA[randomapi]]></category><category><![CDATA[definition]]></category><dc:creator><![CDATA[Keith Armstrong]]></dc:creator><pubDate>Sun, 11 Sep 2016 22:18:20 GMT</pubDate><content:encoded><![CDATA[<p>The getVar function fetches the GET variables from an API query. This gives your API the ability to receive some input data that you could configure to change the output.</p>

<p>Let's make a simple math API for example. In this example, we are basically generating 2 numbers and then performing an operation on them. By default, the program will add the 2 numbers together and then assign the sum to a property called <code>add</code>. In this example, the user can completely change the functionality of this API by changing the operation that is performed by sending in an <code>operation</code> value through the URI.</p>

<p>If the operation passes our validation check, the program will end up using a different operator and result with completely different output.</p>

<pre><code class="language-javascript">// Fetch the value sent in through the operation GET variable
let operation = getVar('operation');

// Accepted operations that we will check against
let validOperations  = ["add", "sub", "mul", "div", "mod"];  
let operationSymbols = [ "+",   "-",   "*",   "/",   "%" ];

// Default value
let useOperation = "add";

// Only use sent in operation if it is in our list of valid operations.
let index = validOperations.indexOf(operation);

if (index !== -1) {  
    useOperation = operation;
} else {
    index = 0; // Add is 0.
}

api.num1 = random.numeric(1, 25);  
api.num2 = random.numeric(1, 25);

api[useOperation] = eval(`${api.num1}${operationSymbols[index]}${api.num2}`);  
</code></pre>

<blockquote>
  <p>/api/1234abcd?key=...&amp;operation=sub</p>
</blockquote>

<pre><code class="language-json">{
  "num1": 15,
  "num2": 6,
  "sub": 9
}
</code></pre>

<p>For this example, the getVar result was fairly simple but it is easy to see how you can configure your API to have completely different behavior depending on the input that is sent in.</p>]]></content:encoded></item><item><title><![CDATA[What is a List?]]></title><description><![CDATA[<p>A list is a text file that you can upload for use with your APIs to easily have a random item (line) returned. You can also use the list function for inline lists if you want to quickly have a random item returned to you. We'll first take a look</p>]]></description><link>https://blog.randomapi.com/what-is-a-list/</link><guid isPermaLink="false">d2497696-7ac2-4cd1-80f7-234e0adfa2e7</guid><category><![CDATA[randomapi]]></category><category><![CDATA[definition]]></category><dc:creator><![CDATA[Keith Armstrong]]></dc:creator><pubDate>Sun, 11 Sep 2016 21:29:00 GMT</pubDate><content:encoded><![CDATA[<p>A list is a text file that you can upload for use with your APIs to easily have a random item (line) returned. You can also use the list function for inline lists if you want to quickly have a random item returned to you. We'll first take a look at the primary usage.</p>

<p>Let's use the <a href="http://keitharm.me/projects/pokemmon/">Pokemon Game Clone</a> that I am working on as an example and use case for the list.</p>

<p>When you upload a list, you'll be given a reference id. This unique identifier is what you'll use to specify the list you want to use in your API. Only your account has access to the contents of this list.</p>

<p><img src="https://blog.randomapi.com/content/images/2016/09/Screen-Shot-2016-09-11-at-4.38.53-PM.png" alt=""></p>

<pre><code class="language-javascript">api.pokemon = list('sx9kqznu');  
</code></pre>

<pre><code class="language-json">{
  "pokemon": "Vulpix"
}
</code></pre>

<p>By default, the <code>list</code> function will choose a random item from the list. You can however specify a line number as the 2nd parameter if you'd like. For my Pokemon Generator, it'd be nice to have a separate id variable generated and then I could use that value to choose the proper line number/pokemon from the list.</p>

<pre><code class="language-javascript">api.id = random.numeric(1, 151);  
api.pokemon = list('sx9kqznu', api.id);  
</code></pre>

<pre><code class="language-json">{
  "id": 112,
  "pokemon": "Rhydon"
}
</code></pre>

<p>As hinted at from before, you can also send an array directly to the list function. The 2nd parameter is also available if you use the list this way, but keep in mind that the index is zero-based for arrays. Let's give the generated pokemon a gender now. It'd be overkill to upload a text file only containing "male" and "female", so let's send in an array!</p>

<pre><code class="language-javascript">api.id = random.numeric(1, 151);  
api.gender = list(['male', 'female']);  
api.pokemon = list('sx9kqznu', api.id);  
</code></pre>

<pre><code class="language-json">{
  "id": 115,
  "gender": "female",
  "pokemon": "Kangaskhan"
}
</code></pre>]]></content:encoded></item><item><title><![CDATA[What is an API?]]></title><description><![CDATA[<p>When you think of an API, you typically think of a web endpoint that your application can request information from or send information to. The API endpoint for RandomAPI is <a href="http://beta.randomapi.com/api">http://beta.randomapi.com/api</a>. You provide your API Key and API Ref ID and have the results that are</p>]]></description><link>https://blog.randomapi.com/what-is-an-api/</link><guid isPermaLink="false">22e4f621-0aba-4183-ae8d-797d66c8ce5b</guid><category><![CDATA[randomapi]]></category><category><![CDATA[definition]]></category><dc:creator><![CDATA[Keith Armstrong]]></dc:creator><pubDate>Sun, 11 Sep 2016 21:17:11 GMT</pubDate><content:encoded><![CDATA[<p>When you think of an API, you typically think of a web endpoint that your application can request information from or send information to. The API endpoint for RandomAPI is <a href="http://beta.randomapi.com/api">http://beta.randomapi.com/api</a>. You provide your API Key and API Ref ID and have the results that are generated from the API you queried for returned to you.  </p>

<blockquote>
  <p><code>http://beta.randomapi.com/api/1234abcd?key=ABCD-1234-EFGH-5678</code></p>
</blockquote>

<p>In the RandomAPI world, an API can be thought of as the Javascript source code that instructs the generator how to generate the random data you want.</p>

<pre><code class="language-javascript">const faker = require('faker');

api.user     = faker.name.findName();  
api.userID   = random.special(4, 5);  
api.password = random.special(3, 8);  
</code></pre>

<pre><code class="language-json">{
  "user": "Mireille Homenick DVM",
  "userID": "10057",
  "password": "Vq8EqJr0"
}
</code></pre>

<p>A RandomAPI API is an API (say that 3x fast) in the sense that you can provide input through the GET variables you send in your URI (<code>?mode=1&amp;list=23</code>) and receive output that is affected by those inputs. But other than that, it is completely different from your run of the mill API.</p>

<hr>

<p>With that definition out of the way, let's get into some technical details regarding APIs.</p>

<p>Every API has an implicit API object appropriately named <code>api</code>. All of the data that you want returned to you when you call your API must be attached to this object as a property. In this example, only the variable <code>a</code> will be returned since it is attached to the <code>api</code> object.  </p>

<pre><code class="language-javascript">// Local variables. If you want to do complicated operations before attaching the result to the api object, local variables can be helpful

let num1 = 4;  
let num2 = 20;  
let a = num1 * num2;  
let b = 5;

// Attach a to the api object.
api.a = a;  
</code></pre>

<pre><code class="language-json">{
  "a": 80
}
</code></pre>

<p>You can also redefine the API object by assigning properties directly if you wish.  </p>

<pre><code class="language-javascript">api = {  
  a: 5,
  b: 6
};
</code></pre>

<pre><code class="language-json">{
  "a": 5,
  "b": 6
}
</code></pre>

<p>You can even set the api object to something other than an object.  </p>

<pre><code class="language-javascript">api = `Billy is ${random.numeric(13,21)} years old and likes the color ${list(['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'])}`  
</code></pre>

<pre><code class="language-json">"Billy is 17 years old and likes the color green"
</code></pre>]]></content:encoded></item><item><title><![CDATA[The RandomAPI 2.0 Beta is out!]]></title><description><![CDATA[<h3 id="randomapi20beta">RandomAPI 2.0 Beta</h3>

<p>It's been about 2 years since I released the the old PHP version of RandomAPI. It was a cool idea that had potential, but looking back, there were many features that weren't fully fleshed out and the generation technology itself could have been much better. Instead</p>]]></description><link>https://blog.randomapi.com/the-randomapi-2-0-beta-is-out/</link><guid isPermaLink="false">93b4c49f-27b8-4eb7-92d0-cf896a86fecb</guid><category><![CDATA[randomapi]]></category><category><![CDATA[announcement]]></category><dc:creator><![CDATA[Keith Armstrong]]></dc:creator><pubDate>Sun, 11 Sep 2016 20:45:00 GMT</pubDate><content:encoded><![CDATA[<h3 id="randomapi20beta">RandomAPI 2.0 Beta</h3>

<p>It's been about 2 years since I released the the old PHP version of RandomAPI. It was a cool idea that had potential, but looking back, there were many features that weren't fully fleshed out and the generation technology itself could have been much better. Instead of trying to reinvent the wheel with my own custom tailored "programming language" and "parser", I should have gone the route of using a language that was easy to learn and widely available and familiar.</p>

<p>That's what RandomAPI 2.0 is!</p>

<p>A complete rewrite from the ground up in Node.js/Express, RandomAPI 2.0 promises to bring some much needed speed and feature improvements along with a much cleaner and less cluttered design.</p>

<p>Old Site <br>
<img src="https://blog.randomapi.com/content/images/2016/09/Screen-Shot-2016-09-11-at-3.26.34-PM.png" alt="">
New Site <br>
<img src="https://blog.randomapi.com/content/images/2016/09/Screen-Shot-2016-09-11-at-3.26.43-PM.png" alt=""></p>

<p>Instead of using an esoteric, homemade language, <a href="http://vanilla-js.com/">Vanilla Javascript</a> is fully supported! Along with speed improvements, something that is familiar, easy to learn, and powerful improves the RandomAPI experience in every way.</p>

<p>Along with all of these huge improvements, RandomAPI 2.0 introduces a new feature that I think will be a big hit: Snippets. Snippets are user defined pieces of code that can be included in an API using the familiar <code>require</code> syntax in Node.js (read about it more <a href="http://beta.randomapi.com/documentation#snippets">here</a>). If you've made a function or data generator that you think would be beneficial for other users, you can publish your snippet for others to import into their APIs! Think of it like NPM for Node.js modules.</p>

<p>And speaking of node modules, "global snippets" are included as well. Global snippets, a.k.a. node modules, are normal modules that you would require in a standalone node program. Some global snippets like <a href="https://www.npmjs.com/package/Faker">Faker</a> and <a href="https://www.npmjs.com/package/moment">Moment</a> can be required into your APIs as well. Overtime, more modules will be added that can be helpful for your APIs. If you have any suggestions, feel free to send us a message!</p>

<p>And that's about it for now! The purpose of this blog will mainly be for updates as well as more in-depth tutorials than what the <a href="https://blog.randomapi.com/the-randomapi-2-0-beta-is-out/beta.randomapi.com/documentation">documentation</a> provides. Thanks for reading!</p>

<p>- Keith</p>]]></content:encoded></item></channel></rss>