131 lines
7.1 KiB
HTML
131 lines
7.1 KiB
HTML
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>ModernAPIClient Documentation</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
</head>
|
|
<body class="bg-light">
|
|
<div class="container mt-5">
|
|
<h1 class="mb-4">ModernAPIClient Documentation</h1>
|
|
|
|
<section>
|
|
<h2>Overview</h2>
|
|
<p>The <code>ModernAPIClient</code> class is designed to simplify API interactions in a web environment. It supports making <code>GET</code> and <code>POST</code> requests, including handling file uploads and securely managing request parameters.</p>
|
|
</section>
|
|
|
|
<section>
|
|
<h2>Initialization</h2>
|
|
<pre><code>const client = new ModernAPIClient('https://api.example.com');</code></pre>
|
|
</section>
|
|
|
|
<section>
|
|
<h2>Memory Optimization and Security</h2>
|
|
<p>When the <code>ModernAPIClient</code> is instantiated, it automatically decrypts and stores certain values (e.g., <code>MemOptimizeMethod</code> and <code>MemStackFrame</code>) that are used to secure API requests. These values are expected to be present as Base64-encoded hidden fields in the HTML page.</p>
|
|
</section>
|
|
|
|
<section>
|
|
<h2>Methods</h2>
|
|
|
|
<h3>1. <code>postAction(controller, action, parameters, secure = false)</code></h3>
|
|
<p>Sends a <code>POST</code> request to a specific controller and action within the API.</p>
|
|
<p><strong>Parameters:</strong></p>
|
|
<ul>
|
|
<li><code>controller</code> (string): The controller name.</li>
|
|
<li><code>action</code> (string): The action name.</li>
|
|
<li><code>parameters</code> (object): An object containing key-value pairs to be sent as the POST body.</li>
|
|
<li><code>secure</code> (boolean): If <code>true</code>, the request will be secured with additional parameters.</li>
|
|
</ul>
|
|
<p><strong>Returns:</strong> A <code>Promise</code> that resolves with the response data.</p>
|
|
|
|
<h4>Example:</h4>
|
|
<pre><code>const parameters = { param1: 'value1' };
|
|
client.postAction('exampleController', 'exampleAction', parameters)
|
|
.then(response => console.log('POST Action Result:', response))
|
|
.catch(error => console.error('Error in POST Action:', error));</code></pre>
|
|
|
|
<h3>2. <code>postFileAction(controller, action, fileName, secure = false)</code></h3>
|
|
<p>Sends a <code>POST</code> request to upload a file to a specific controller and action within the API.</p>
|
|
<p><strong>Parameters:</strong></p>
|
|
<ul>
|
|
<li><code>controller</code> (string): The controller name.</li>
|
|
<li><code>action</code> (string): The action name.</li>
|
|
<li><code>fileName</code> (string): The file to be uploaded.</li>
|
|
<li><code>secure</code> (boolean): If <code>true</code>, the request will be secured with additional parameters.</li>
|
|
</ul>
|
|
<p><strong>Returns:</strong> A <code>Promise</code> that resolves with the response data.</p>
|
|
|
|
<h4>Example:</h4>
|
|
<pre><code>const fileInput = document.getElementById('fileInput');
|
|
const file = fileInput.files[0];
|
|
client.postFileAction('uploadController', 'uploadAction', file)
|
|
.then(response => console.log('File Upload Result:', response))
|
|
.catch(error => console.error('Error in File Upload:', error));</code></pre>
|
|
|
|
<h3>3. <code>getAction(controller, action, parameters, secure = false)</code></h3>
|
|
<p>Sends a <code>GET</code> request to a specific controller and action within the API.</p>
|
|
<p><strong>Parameters:</strong></p>
|
|
<ul>
|
|
<li><code>controller</code> (string): The controller name.</li>
|
|
<li><code>action</code> (string): The action name.</li>
|
|
<li><code>parameters</code> (object): An object containing key-value pairs to be sent as query string parameters.</li>
|
|
<li><code>secure</code> (boolean): If <code>true</code>, the request will be secured with additional parameters.</li>
|
|
</ul>
|
|
<p><strong>Returns:</strong> A <code>Promise</code> that resolves with the response data.</p>
|
|
|
|
<h4>Example:</h4>
|
|
<pre><code>const parameters = { param1: 'value1' };
|
|
client.getAction('exampleController', 'exampleAction', parameters)
|
|
.then(response => console.log('GET Action Result:', response))
|
|
.catch(error => console.error('Error in GET Action:', error));</code></pre>
|
|
|
|
<h3>4. <code>getStatic(staticRoute, parameters, secure = false)</code></h3>
|
|
<p>Sends a <code>GET</code> request to a specific static route within the API.</p>
|
|
<p><strong>Parameters:</strong></p>
|
|
<ul>
|
|
<li><code>staticRoute</code> (string): The static route.</li>
|
|
<li><code>parameters</code> (object): An object containing key-value pairs to be sent as query string parameters.</li>
|
|
<li><code>secure</code> (boolean): If <code>true</code>, the request will be secured with additional parameters.</li>
|
|
</ul>
|
|
<p><strong>Returns:</strong> A <code>Promise</code> that resolves with the response data.</p>
|
|
|
|
<h4>Example:</h4>
|
|
<pre><code>const parameters = { param1: 'value1' };
|
|
client.getStatic('/staticRoute', parameters)
|
|
.then(response => console.log('GET Static Result:', response))
|
|
.catch(error => console.error('Error in GET Static:', error));</code></pre>
|
|
</section>
|
|
|
|
<section>
|
|
<h2>Secure Requests</h2>
|
|
<p>For secure API interactions, set the <code>secure</code> parameter to <code>true</code> in any of the methods. This will add additional parameters, such as a timestamp and values from decrypted memory, to the request.</p>
|
|
</section>
|
|
|
|
<section>
|
|
<h2>Example Workflow</h2>
|
|
<pre><code>// Initialize the client with the base API URL
|
|
const client = new ModernAPIClient('https://api.example.com');
|
|
|
|
// Perform a secure POST request
|
|
const postParams = { param1: 'value1', param2: 'value2' };
|
|
client.postAction('myController', 'myAction', postParams, true)
|
|
.then(response => console.log('POST Response:', response))
|
|
.catch(error => console.error('POST Error:', error));
|
|
|
|
// Perform a secure GET request
|
|
const getParams = { param1: 'value1' };
|
|
client.getAction('myController', 'myGetAction', getParams, true)
|
|
.then(response => console.log('GET Response:', response))
|
|
.catch(error => console.error('GET Error:', error));</code></pre>
|
|
</section>
|
|
|
|
<section>
|
|
<h2>Conclusion</h2>
|
|
<p>The <code>ModernAPIClient</code> class is a powerful tool for interacting with RESTful APIs in a web environment. It offers flexibility with its secure request options and supports a variety of request types, including file uploads. By following the examples provided, you can easily integrate this class into your web applications.</p>
|
|
</section>
|
|
</div>
|
|
</body>
|
|
</html>
|