🌐 AppML API & References
Estimated reading: 4 minutes 32 views

βš™οΈ AppML – Common API Methods: Master Data Interaction with CRUD

🧲 Introduction – What Are AppML API Methods?

AppML uses a simplified, HTML-friendly approach to interact with backend services through standard API methods. Whether you’re fetching records, saving form data, or filtering tables, AppML supports the most common HTTP-based operationsβ€”without writing JavaScript or external libraries.

🎯 In this article, you’ll learn:

  • The most common AppML API methods (GET, POST, PUT, DELETE)
  • How each method is used with appml-data and appml-submit
  • Examples of real-world use: fetching data, saving forms, deleting records
  • Backend handling tips for PHP, Node.js, and other stacks

πŸ”Œ What Are AppML API Methods?

AppML supports the following common HTTP methods to communicate with APIs:

🌐 MethodπŸ”§ PurposeπŸ” Usage in AppML
GETRetrieve dataAuto-triggered by appml-data
POSTCreate new dataTriggered on form submission
PUTUpdate dataTriggered when record has id
DELETEDelete recordManually triggered via controller

These map directly to standard CRUD operations.


πŸ§ͺ 1. GET – Fetch Data from API

βœ… Example: Fetch and Display Users

<div appml-data="api/users.php">
  <p>{{name}} – {{email}}</p>
</div>

βœ… Sample users.php

echo json_encode([
  ["name" => "Alice", "email" => "alice@example.com"],
  ["name" => "Bob", "email" => "bob@example.com"]
]);

πŸ”„ AppML uses GET to fetch this JSON and render it using the view.


πŸ“ 2. POST – Submit New Data via Form

When a user fills out a form and hits a button with appml-submit, AppML sends a POST request with the form data.

βœ… HTML Form Example

<div appml-model="models/product-model.json" appml-data="api/save-product.php">
  <input name="name">
  <input name="price" type="number">
  <button appml-submit>Add Product</button>
</div>

βœ… Backend (save-product.php)

$data = json_decode(file_get_contents("php://input"), true);
// Save $data['name'], $data['price'] to database...

πŸ“¦ AppML automatically sends a JSON payload.


πŸ” 3. PUT – Update Existing Record

When a form includes a primary key (e.g., id), AppML switches from POST to PUT, meaning you’re editing an existing record.

βœ… Example

<input name="id" value="23" hidden>
<input name="name" value="Updated Product">

AppML detects the id and uses a PUT request to update the data.


πŸ—‘οΈ 4. DELETE – Remove a Record

Deletion is typically triggered manually through a controller function:

βœ… Delete Record via Controller

function deleteItem() {
  myAppML.deleteRecord();
}

βœ… This sends a DELETE request with the record’s ID, based on the model’s primary key.


🧠 Best Practices for API Methods

πŸ’‘ Tipβœ… Why It Matters
Use id to determine POST vs PUTAppML switches based on presence of ID
Return proper HTTP codesHelps AppML handle response correctly
Validate inputs on serverAvoids malicious requests
Sanitize data before DB insertPrevents SQL injection
Send back a success messageUseful for myAppML.message display

πŸ“Œ Summary – Recap & Key Takeaways

AppML integrates tightly with backend APIs using standard methods like GET, POST, PUT, and DELETE. These actions allow seamless data interaction through clean HTML syntax and optional controller logic.

πŸ” Key Takeaways:

  • Use appml-data to trigger GET on page load
  • Use appml-submit to trigger POST or PUT depending on the presence of id
  • Trigger DELETE with myAppML.deleteRecord()
  • Backends must accept and respond to JSON payloads
  • Use proper security, validation, and messaging practices

βš™οΈ These API methods make AppML a great choice for building real CRUD apps without a heavy framework.


❓ FAQs – Common API Methods in AppML


❓ How does AppML decide between POST and PUT?
βœ… If the model includes a primary key (id) and it’s filled in, AppML sends a PUT. Otherwise, it uses POST.


❓ Can I use query parameters in the URL?
βœ… Yes. AppML supports appml-data="api/users.php?status=active" for filtered queries.


❓ Is DELETE handled automatically?
❌ No. You must trigger it manually with myAppML.deleteRecord() or custom logic.


❓ Can I override the HTTP method manually?
⚠️ Not directly in HTML, but you can override it in your backend or by modifying myAppML.httpMethod.


❓ Do I need to return any specific format?
βœ… Return application/json or application/xml. JSON is preferred for compatibility.


Share Now :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

AppML – Common API Methods

Or Copy Link

CONTENTS
Scroll to Top