Intro Python Web API
MAXServer Logo

MAX Server

Introduction Python Web API Reference
MAXServer Logo

MAX Server API

Introduction to MAX Server API

MAX Server is a powerful platform for managing JSON, HTML, CSS files and image uploads. This documentation provides comprehensive guidance on using the RESTful API endpoints available at https://api-code.ir/max/.

Authentication

Secure user authentication system with login and registration capabilities. All API operations require valid credentials.

File Management

Complete CRUD operations for various file types. Create, read, update, delete, lock and unlock files with precision.

Image Upload

Efficient image uploading system supporting popular formats like JPG, PNG, and GIF with a maximum size of 5MB.

File Formats

Full support for various file formats including JSON, HTML, and CSS with specialized endpoints for each type.

Getting Started

To begin using the MAX Server API, you'll need to:

  1. Register an account or login with existing credentials
  2. Use your authentication tokens for subsequent API calls
  3. Follow the specific endpoints documentation for each operation

The API is designed to be RESTful and straightforward, making it easy to integrate with your applications.

Python Implementation

Below is a complete Python implementation for interacting with MAX Server API using the requests library.

import requests
import json

API_BASE = 'https://api-code.ir/max/'

def login(username, password):
    """Authenticate with MAX Server"""
    url = f'{API_BASE}m.php'
    data = {'username': username, 'pass': password}
    response = requests.post(url, data=data)
    if 'error' in response.text:
        return None
    return json.loads(response.text)[0]

def register(username, password, email):
    """Register new user"""
    url = f'{API_BASE}m2.php'
    data = {'username': username, 'pass': password, 'email': email}
    response = requests.post(url, data=data)
    return response.text == 'ok'

Installation

pip install requests

The requests library is the only dependency required for this implementation.

Running the Script

python max_server_api.py

Save the code to a file named max_server_api.py and run it with Python 3.

Best Practices

  • Error Handling Always implement proper error handling for network requests to prevent application crashes.
  • Credential Security Store credentials securely, preferably in environment variables or a configuration file outside version control.
  • Request Throttling Consider implementing request throttling for bulk operations to avoid overwhelming the server.

Web Implementation

Below is a complete implementation for interacting with MAX Server API using HTML, CSS, and JavaScript.

<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>مکس سرور - نمونه وب</title>
  <script src="https://cdn.tailwindcss.com"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
  <link href="https://fonts.googleapis.com/css2?family=Google+Sans:wght@300;400;500;700&display=swap" rel="stylesheet">
  <style>
    :root {
      --bg-color: #0d1117;
      --card-color: #161b22;
      --text-color: #b0c6ff;
      --btn-bg: #b0c6ff;
      --btn-text-dark: #151a2d;
      --menu-bg: #0d1017;
      --accent-color: #b0c6ff;
    }
    
    body {
      margin: 0;
      font-family: 'Google Sans', sans-serif;
      background-color: var(--bg-color);
      color: var(--text-color);
    }
    
    .card {
      background: var(--card-color);
      border-radius: 16px;
      box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
      transition: transform 0.3s ease, box-shadow 0.3s ease;
    }
    
    .card:hover {
      transform: translateY(-5px);
      box-shadow: 0 12px 24px rgba(0, 0, 0, 0.3);
    }
    
    .btn-primary {
      background-color: var(--btn-bg);
      color: var(--btn-text-dark);
      border-radius: 12px;
      padding: 0.75rem 1.5rem;
      font-weight: 500;
      transition: all 0.3s ease;
    }
    
    .btn-primary:hover {
      opacity: 0.9;
      transform: translateY(-2px);
    }
    
    .btn-secondary {
      background-color: transparent;
      color: var(--text-color);
      border: 1px solid var(--text-color);
      border-radius: 12px;
      padding: 0.75rem 1.5rem;
      font-weight: 500;
      transition: all 0.3s ease;
    }
    
    .btn-secondary:hover {
      background-color: rgba(176, 198, 255, 0.1);
    }
    
    .input-field {
      background-color: rgba(13, 17, 23, 0.7);
      border: 1px solid rgba(176, 198, 255, 0.3);
      border-radius: 8px;
      padding: 0.75rem 1rem;
      color: var(--text-color);
      width: 100%;
    }
    
    .input-field:focus {
      outline: none;
      border-color: var(--accent-color);
      box-shadow: 0 0 0 2px rgba(176, 198, 255, 0.2);
    }
    
    .hidden {
      display: none;
    }
  </style>
</head>
<body class="min-h-screen p-4">
  <div class="max-w-5xl mx-auto">
    <header class="text-center mb-8">
      <div class="flex items-center justify-center mb-4">
        <img src="http://max-server.ir/MAXServer.jpg" alt="MAX Server" class="w-16 h-16 rounded-full shadow-lg">
      </div>
      <h1 class="text-3xl font-bold mb-2">مدیریت فایل‌ها در MAX Server</h1>
      <p class="text-[#b0c6ff]/80">یک نمونه وب برای استفاده از API مکس سرور</p>
    </header>
    
    <!-- Login Section -->
    <section id="loginSection" class="card p-6 max-w-md mx-auto">
      <h2 class="text-2xl font-bold mb-6 text-center">ورود به سیستم</h2>
      <form id="loginForm" class="space-y-4">
        <div>
          <label class="block mb-1">نام کاربری</label>
          <input type="text" name="username" placeholder="نام کاربری خود را وارد کنید" 
                 class="input-field" required>
        </div>
        <div>
          <label class="block mb-1">رمز عبور</label>
          <input type="password" name="pass" placeholder="رمز عبور خود را وارد کنید" 
                 class="input-field" required>
        </div>
        <button type="submit" class="btn-primary w-full">
          ورود
        </button>
      </form>
      <div id="loginError" class="mt-4 p-3 bg-red-900/20 text-red-400 rounded-lg hidden"></div>
      
      <div class="mt-6 text-center">
        <p>حساب کاربری ندارید؟</p>
        <button id="showRegisterBtn" class="text-[#b0c6ff] hover:underline">ثبت‌نام کنید</button>
      </div>
    </section>
    
    <!-- Register Section -->
    <section id="registerSection" class="card p-6 max-w-md mx-auto hidden">
      <h2 class="text-2xl font-bold mb-6 text-center">ایجاد حساب کاربری</h2>
      <form id="registerForm" class="space-y-4">
        <div>
          <label class="block mb-1">نام کاربری</label>
          <input type="text" name="username" placeholder="یک نام کاربری انتخاب کنید" 
                 class="input-field" required>
        </div>
        <div>
          <label class="block mb-1">ایمیل</label>
          <input type="email" name="email" placeholder="ایمیل خود را وارد کنید" 
                 class="input-field" required>
        </div>
        <div>
          <label class="block mb-1">رمز عبور</label>
          <input type="password" name="pass" placeholder="یک رمز عبور انتخاب کنید" 
                 class="input-field" required>
        </div>
        <button type="submit" class="btn-primary w-full">
          ثبت‌نام
        </button>
      </form>
      <div id="registerError" class="mt-4 p-3 bg-red-900/20 text-red-400 rounded-lg hidden"></div>
      
      <div class="mt-6 text-center">
        <p>قبلاً ثبت‌نام کرده‌اید؟</p>
        <button id="showLoginBtn" class="text-[#b0c6ff] hover:underline">وارد شوید</button>
      </div>
    </section>
    
    <!-- Dashboard Section -->
    <section id="dashboardSection" class="hidden">
      <div class="flex justify-between items-center mb-6">
        <h2 class="text-2xl font-bold">داشبورد</h2>
        <div class="flex items-center">
          <span id="userInfo" class="mr-4"></span>
          <button id="logoutBtn" class="btn-secondary">
            خروج
          </button>
        </div>
      </div>
      
      <div class="grid grid-cols-1 md:grid-cols-3 gap-8">
        <!-- Create File Card -->
        <div class="card p-6">
          <h3 class="text-xl font-bold mb-4">ایجاد فایل جدید</h3>
          <form id="createFileForm" class="space-y-4">
            <div>
              <label class="block mb-1">نوع فایل</label>
              <select name="type" class="input-field">
                <option value="json">JSON</option>
                <option value="html">HTML</option>
                <option value="css">CSS</option>
              </select>
            </div>
            <div>
              <label class="block mb-1">نام فایل</label>
              <input type="text" name="name" placeholder="نام فایل بدون پسوند" 
                     class="input-field" required>
            </div>
            <div>
              <label class="block mb-1">رمز فایل</label>
              <input type="password" name="password" placeholder="رمز فایل" 
                     class="input-field" required>
            </div>
            <button type="submit" class="btn-primary w-full">
              ایجاد فایل
            </button>
          </form>
          <div id="createFileError" class="mt-4 p-3 bg-red-900/20 text-red-400 rounded-lg hidden"></div>
          <div id="createFileSuccess" class="mt-4 p-3 bg-green-900/20 text-green-400 rounded-lg hidden"></div>
        </div>
        
        <!-- File List -->
        <div class="card p-6 md:col-span-2">
          <div class="flex justify-between items-center mb-4">
            <h3 class="text-xl font-bold">لیست فایل‌ها</h3>
            <button id="refreshFilesBtn" class="btn-secondary text-sm py-1 px-3">
              بروزرسانی
            </button>
          </div>
          
          <div class="mb-4">
            <div class="flex space-x-2 rtl:space-x-reverse">
              <button class="file-type-btn bg-[#b0c6ff] text-[#151a2d] px-3 py-1 rounded-lg" data-type="json">
                JSON
              </button>
              <button class="file-type-btn bg-[#161b22] text-[#b0c6ff] border border-[#b0c6ff]/30 px-3 py-1 rounded-lg" data-type="html">
                HTML
              </button>
              <button class="file-type-btn bg-[#161b22] text-[#b0c6ff] border border-[#b0c6ff]/30 px-3 py-1 rounded-lg" data-type="css">
                CSS
              </button>
            </div>
          </div>
          
          <div id="fileList" class="space-y-2 max-h-80 overflow-y-auto p-2">
            <div class="loading flex justify-center py-4">
              <div class="animate-spin rounded-full h-8 w-8 border-b-2 border-[#b0c6ff]"></div>
            </div>
          </div>
        </div>
      </div>
      
      <!-- File Content Section -->
      <div id="fileContentSection" class="mt-8 card p-6 hidden">
        <div class="flex justify-between items-center mb-4">
          <h3 class="text-xl font-bold">محتوای فایل: <span id="currentFileName"></span></h3>
          <button id="closeFileBtn" class="btn-secondary py-1 px-3">
            بستن
          </button>
        </div>
        <div id="fileContent" class="bg-[#0d1117] p-4 rounded-lg h-64 overflow-auto"></div>
      </div>
    </section>
  </div>
</body>
</html>

API Reference

Complete reference for all available MAX Server API endpoints.

Endpoint Method Description Parameters
/m.php
POST User login username pass
/m2.php
POST User registration username pass email
/{type}nm/Cfile.php
POST Create file username upassword name password type
/{type}nm/edit.php
POST Edit file content username upassword name content
/{type}nm/Get.php
POST Get file list username pass
/{type}nm/lock.php
GET Lock file name username password
/{type}nm/un_lock.php
GET Unlock file name username password
/{type}nm/Rfile.php
POST Delete file username name password
/{type}nm/fetch.php
GET Fetch file content name type

Replacing "{type}"

In the endpoints above, replace {type} with one of the following values depending on the file type:

  • json - For JSON files
  • html - For HTML files
  • css - For CSS files

Response Formats

  • Success responses:
    // For login (m.php)
    [{"id":"2","username":"user","pass":"password","email":"user@example.com"}]
    
    // For other operations
    ok
  • Error responses:
    error-user

Security Considerations

  • Password Storage The API currently stores passwords as plain text. For production applications, implement additional encryption on your client-side.
  • HTTPS Always use HTTPS for API requests to prevent data interception during transmission.
  • Validate Input Always validate and sanitize user input on your client-side before sending it to the API.