AppML β API Overview: Power Your AppML Apps with Dynamic Data
Introduction β What Is the AppML API?
AppML is not just a model-view binding frameworkβit also supports API-driven development. You can connect your AppML views to RESTful APIs, server scripts (PHP/ASP), or even JSON and XML endpoints using simple HTML attributes. This makes it easy to build dynamic, data-driven web appsβwithout needing JavaScript libraries.
In this guide, youβll learn:
- How AppML uses APIs to fetch and update data
- Supported request types: GET, POST, PUT, DELETE
- API structure for client-server communication
- Real-world use cases and code examples
What Is the AppML API?
The AppML API is not a standalone framework or serviceβrather, it’s how AppML communicates with backend servers. You define your model and link it to an API endpoint via the appml-data attribute. This endpoint can return data, handle form submissions, and perform CRUD operations.
Basic API Workflow in AppML
| Step | Description |
|---|---|
appml-data | Specifies the API URL or server endpoint |
appml-model | Defines how to structure, validate, and bind the data |
| Controller logic | Adds filters, sort options, or validation |
| View | Automatically updates with API response |
Example: Loading Data from an API
HTML
<div appml-model="models/user-model.json" appml-data="api/get-users.php">
<p>{{name}} β {{email}}</p>
</div>
get-users.php
<?php
$users = [
["name" => "Alice", "email" => "alice@example.com"],
["name" => "Bob", "email" => "bob@example.com"]
];
echo json_encode($users);
?>
AppML fetches and renders this data using the model definition.
Supported API Operations in AppML
| HTTP Method | AppML Operation | Example Use Case |
|---|---|---|
GET | Read | Load users, products, etc. |
POST | Create | Add a new record from a form |
PUT | Update | Edit existing record |
DELETE | Delete | Remove an item (manually coded) |
Example: Form Submission via POST
<div appml-model="models/product-model.json" appml-data="api/save-product.php">
<input name="name">
<input name="price" type="number">
<button appml-submit>Save</button>
</div>
AppML sends the form as JSON to save-product.php.
Controller Logic to Enhance API Calls
You can dynamically control how data is sent to or retrieved from your API:
myAppML.onshow = function() {
myAppML.sqlfilter = "price > 100";
};
myAppML.onsubmit = function() {
myAppML.message = "Product saved successfully!";
return true;
};
Securing AppML API Endpoints
While AppML handles client-side rendering, make sure your server-side API:
- Validates and sanitizes all inputs
- Restricts access via authentication/authorization
- Escapes SQL queries to prevent injection
- Sends proper HTTP status codes
Use Cases for API in AppML
| Scenario | API Integration Example |
|---|---|
| Admin dashboard | Load users, stats, and analytics |
| Product management | Create/edit/delete products |
| Customer data forms | Submit feedback or registration |
| Reporting system | Load report data via JSON API |
| Remote filtering/search | Apply filters on server response |
Summary β Recap & Key Takeaways
AppML uses API endpoints to fetch, filter, and save data with no JavaScript coding required. This allows you to connect your frontend to any modern backend using REST-style services or custom PHP scripts.
Key Takeaways:
- Use
appml-datato define your API endpoint - Combine with
appml-modelfor structured input and validation - Supports full CRUD with GET/POST/PUT/DELETE
- Use controllers to apply filters, sorting, and form handling
- API responses must return JSON or XML for compatibility
With AppML APIs, you can build lightweight, dynamic apps that talk to real serversβall from HTML.
FAQs β AppML API Usage
Can I use third-party REST APIs with AppML?
Yes, as long as they return data in JSON or XML and CORS is enabled.
What format should my server return?
AppML supports both JSON arrays and XML records. JSON is preferred.
Does AppML handle HTTP errors?
No automatic error alerts. Use myAppML.message to show error responses.
Can I send authentication tokens with requests?
Yes, by customizing your controller to include headers or query params (with backend support).
Is AppML compatible with Node.js or Python backends?
Yes. Any backend that sends/receives JSON can work with AppML seamlessly.
Share Now :
