You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>RandomAPI includes some basic data generation functions that your API can make use of. All of these included functions respect the <b>seed</b> value that is sent in through an API request (except for timestamp since it returns the <b>current</b> time).</p>
<p>Chooses a random (or specified) item from either a list or provided array. If no lineNumber or indexNumber is provided, a random item will be chosen from the list or array respectively.</p>
135
135
<tableclass="u-full-width">
136
136
<thead>
@@ -161,7 +161,7 @@ list(["male", "female"], 1); // female</code></pre>Warning: Indexes are zero bas
<p>You can also access some internal variables as well with getVar. This could be useful if you wanted access to the string/numeric seed that the generator is using or maybe wanted to know the format your API was being requested with.</p>
<p>Some other good to know things regarding the generator.</p>
245
+
<ul>
246
+
<li>The generator uses internal variables that start with _API, so avoid using variables in that namespace if you can or else unexpected behavior can happen.</li>
247
+
</ul>
248
+
<p>If you have made an API/Snippet that requires a PRNG, you can access the generators internal PRNG with the prng function. This will return, direct from the Mersenne Twister module the generator is using, a number on [0,1) real interval.
<p>While native, built-in modules aren't accessible through require, some libraries that we have found helpful for generating data will be added to the RandomAPI generators for use in your APIs. Currently, the following modules are available using require:</p>
<p>If you have a suggestion for a module that we should add, send us a tweet or DM <ahref="https://twitter.com/randomapi"class='green'target="_blank">@RandomAPI</a>.</p>
<p>Snippets are user defined pieces of code that you can include in your API. If you have an idea of a helpful function that you'd like to share for others to use, you can make a snippet!</p>
288
+
<p>Snippets are user defined pieces of code that you can include in your API. If you've made a snippet that you'd like to share for others to use, you can publish your snippet!</p>
223
289
<p>Snippets are coded in basically the same way as a normal API except for these key differences:</p>
224
290
<ul>
225
291
<li>Objects are attached to the <b>snippet</b> object instead of the <b>api</b> object.</li>
226
-
<li>Only Global Requires can be used in your snippet. You can't require other snippets from your snippet.</li>
292
+
<li>Only Global Snippets can be used in your snippet. You can't require other snippets from your snippet.</li>
227
293
<li>Snippet names <b>must</b> be unique in regards to your account.</li>
<p>If you've made an awesome snippet that you think would be useful for others, you can publish it!<br>
374
+
Here are some basic rules and tips on publishing snippets</p>
375
+
<ul>
376
+
<li>Once published, snippets can not be removed.</li>
377
+
<ol>This is to prevent other users' APIs from breaking unexpectedly. Make sure that you really want to publish a snippet before you click confim.</ol>
378
+
<li>Published snippets will be given a revision number that starts at 1.</li>
379
+
<ol>Once a snippet is published, you must provide a version number in the snippet signature when you use the require function.</ol>
380
+
<li>Source code of revisions that are published can not be modified. You can still modify the revision's description though.</li>
381
+
<li>If you have made a mistake or want to make an improvement to a snippet, you can create a new revision.</li>
382
+
<li>Users can search for snippets by clicking the search menu item.</li>
383
+
<ol>Search depends on the tags/keywords that you give a snippet. Make sure that you provide good tags that users will most likely search for in order to have the best chance of your snippet being found.</ol>
<p>APIs can be accessed through via the <ahref="https://randomapi.com/api"class='green'target="_blank">https://randomapi.com/api</a> endpoint.</p>
387
+
<p>APIs can be accessed via the <ahref="<%=basehref%>api"class='green'target="_blank"><%=basehref%>api</a> endpoint.</p>
299
388
<p>At a minimum, the endpoint requires a <b>key</b> and <b>ref</b> value or a public hash value. Key would be your API key and ref is the Ref ID of the API you want to access which can be found on the <ahref="view/api"class='green'target="_blank">View APIs</a> page.</p>
300
389
<p>Public hashes are another way that you can access your API without accidentally exposing your API Key and API Ref ID. The user segment of the info block from your results will also be removed by default when your API is called using this method. They can be found by clicking <b>Run API (public URL)</b> on the <ahref="view/api"class='green'target="_blank">View APIs</a> page.</p>
301
390
<p>APIs can be called in three different ways:</p>
302
-
<pre><codeclass="html">https://randomapi.com/api/<spanclass='green'>1234abcd</span>?key=<spanclass='green'>ABCD-1234-EFGH-5678</span> // Ref value is implied
303
-
https://randomapi.com/api/?key=<spanclass='green'>ABCD-1234-EFGH-5678</span>&ref=<spanclass='green'>1234abcd</span> // Ref value is explicitly stated
304
-
https://randomapi.com/api/<spanclass='green'>1234567890abcdef1234567890abcdef</span> // Public hash</code></pre>
391
+
<pre><codeclass="html"><%=basehref%>api/<spanclass='green'>1234abcd</span>?key=<spanclass='green'>ABCD-1234-EFGH-5678</span> // Ref value is implied
392
+
<%=basehref%>api/?key=<spanclass='green'>ABCD-1234-EFGH-5678</span>&ref=<spanclass='green'>1234abcd</span> // Ref value is explicitly stated
393
+
<%=basehref%>api/<spanclass='green'>1234567890abcdef1234567890abcdef</span> // Public hash</code></pre>
<p>You can add extra parameters to your API call to transform your data into different formats, specify how many results you'd like to generate, specify a seed, and even communicate with your api through the <b>getVar</b> function</p>
0 commit comments