🌟 Greetings, B4X enthusiasts! Today, I'm thrilled to unveil the magic behind our latest creation—the Magic API. Elevate your B4X applications with streamlined API integration, simplifying CRUD operations effortlessly. From uploading api.php to securing your connection data, this library is your key to seamless integration. Explore its advantages and fortify your data integrity with advanced security measures. Let's dive into the API revolution!
http://example.com/api.phpapi.php file to your server.Note: The API works fine without the library, but the library will help you communicate more easily.
http://example.com/api.php
api_key (required): Unique key for request authentication.
Parameters:
table (required): Name of the table to retrieve records from.id (optional): ID of the specific record to retrieve.column and value (optional): Name of a column and its value to filter records.comparison (optional): Comparison operator (>, <, >=, or <=).Parameters:
table (required): Name of the table to create a new record.Parameters:
table (required): Name of the table to update a record.id (required): ID of the specific record to update.Parameters:
table (required): Name of the table to delete records from.id or column and value (required): ID or column and value to filter records.comparison (optional): Comparison operator (>, <, >=, or <=).Retrieve all records from a table:
GET api.php?table=example&api_key=your_api_key
Retrieve a specific record by ID:
GET api.php?table=example&id=1&api_key=your_api_key
Retrieve records filtered by a column and its value:
GET api.php?table=example&column=age&value=25&api_key=your_api_key
Retrieve records with comparison:
GET api.php?table=example&column=age&value=25&comparison=>&api_key=your_api_key
Create a new record in a table:
POST /api.php?table=example&api_key=your_api_key
{
"name": "John Doe",
"age": 30,
"email": "johndoe@example.com"
}
Update a record by ID in the "example" table:
PUT api.php?table=example&id=1&api_key=your_api_key
Request Body:
{
"age": 30
}
Update records by column and value in the "example" table:
PUT api.php?table=example&column=name&value=John&api_key=your_api_key
Request Body:
{
"age": 30
}
Update records by comparison:
PUT /api.php?table=example&column=age&value=25&comparison=>&api_key=your_api_key
{
"age": 35
}
Delete a record by ID in the "example" table:
DELETE /api.php?table=example&id=1&api_key=your_api_key
Delete records by column and value in the "example" table:
DELETE /api.php?table=example&column=age&value=25&api_key=your_api_key
Delete records by comparison:
DELETE /api.php?table=example&column=age&value=25&comparison=>&api_key=your_api_key
This library provides methods for performing CRUD (Create, Read, Update, Delete) operations on an API. It is designed to interact with an API that uses JSON as the data exchange format.
1. Download the `MagicApi.b4xlib` library file.
2. Copy the MagicApi.b4xlib file to the additional libraries folder in your B4X development environment.
Before using the library methods, you need to initialize it by calling the `Initialize` method and providing the following parameters:
The library generates response events for each CRUD operation. These events should be implemented in the specified callback module during initialization.
Insertmaps(maps As Map, tablename As String)
Performs an insertion operation on the specified table of the API.
Example usage:
Dim data As Map
data.Initialize
data.Put("Column1", "Value1")
data.Put("Column2", "Value2")
MagicApi.Insertmaps(data, "table")
Delete(tablename As String, id As String)
Deletes a record from the specified table of the API using the ID.
Example usage:
MagicApi.Delete("table", "12")
DeleteByColumn(tablename As String, column As String, value As String)
Deletes records from the specified table of the API using a column and a value.
Example usage:
MagicApi.DeleteByColumn("table", "column", "value")
DeleteByColumn_comparison(tablename As String, column As String, value As String, comparison As String)
Deletes records from the specified table of the API using a column and a value and comparison <,>,<=,>=.
Example usage:
MagicApi.DeleteByColumn_comparison("table", "age", "20", ">")
Update(tablename As String, id As String, data As Map)
Updates a record in the specified table of the API using the ID and the provided data.
Example usage:
Dim data As Map
data.Initialize
data.Put("Column1", "NewValue1")
data.Put("Column2", "NewValue2")
MagicApi.Update("table", "12", data)
UpdateByColumn(tablename As String, column As String, value As String, data As Map)
Updates records in the specified table of the API using a column, a value, and the provided data.
Example usage:
Dim data As Map
data.Initialize
data.Put("Column1", "NewValue1")
data.Put("Column2", "NewValue2")
MagicApi.UpdateByColumn("table", "column", "value", data)
UpdateByColumn_comparison(tablename As String, column As String, value As String, comparison As String, data As Map)
Updates records in the specified table of the API using a column, a value, and the provided data and comparison <,>,>=,<=.
Example usage:
Dim data As Map
data.Initialize
data.Put("Column1", "NewValue1")
data.Put("Column2", "NewValue2")
MagicApi.UpdateByColumn_comparison("table", "age", "15", ">=", data)
SearchforId(tablename As String, id As String)
Searches for a record in the specified table of the API using the ID.
Example usage:
MagicApi.SearchforId("table", "123")
Wait For eventname_SearchforId(m As Map, success As Boolean)
If success = True Then
m.Get("Column 1")
m.Get("Column 2")
Else
' Handle failure
End If
GetTable(tablename As String)
Gets all records from the specified table of the API.
Example usage:
MagicApi.GetTable("table")
Wait For eventname_GetTable(x As List, success As Boolean)
For Each col As Map In x
col.Get("Column name1")
col.Get("Column name 2")
Next
Search(tablename As String, column As String, value As String)
Performs a search in the specified table of the API using a column and a value.
Example usage:
MagicApi.Search("table", "column", "value")
Wait For EventName_Search(x As List, success As Boolean)
If success = True Then
For Each col As Map In x
col.Get("Column name1")
col.Get("Column name 2")
Next
Else
' Handle failure
End If
Search_comparison(tablename As String, column As String, value As String, comparison As String)
Performs a search in the specified table of the API using a column and a value and comparison.
Example usage:
MagicApi.Search_comparison("table", "age", "35", "<=")
Wait For EventName_Search(x As List, success As Boolean)
If success = True Then
For Each col As Map In x
col.Get("Column name1")
col.Get("Column name 2")
Next
Else
' Handle failure
End If
Example implementation in B4X:
Sub Process_Globals
Private magicApi As MagicApi
End Sub
Sub Globals
' ...
End Sub
Sub Activity_Create(FirstTime As Boolean)
' ...
magicApi.Initialize(Me, "MyEventName", "http://example.com")
End Sub
' Implement the events generated by the library
Sub MyEventName_Insertmaps(m As Map, success As Boolean)
' ...
End Sub
Sub MyEventName_Delete(tablename As String, success As Boolean)
' ...
End Sub
' Implement other generated events...
Sub SomeSub
' Examples of using the library methods
Dim data As Map
data.Initialize
data.Put("Column1", "Value1")
data.Put("Column2", "Value2")
magicApi.Insertmaps(data, "table")
magicApi.Delete("table", "123")
magicApi.DeleteByColumn("table", "column", "value")
Dim updateData As Map
updateData.Initialize
updateData.Put("Column1", "NewValue1")
updateData.Put("Column2", "NewValue2")
magicApi.Update("table", "123", updateData)
magicApi.UpdateByColumn("table", "column", "value", updateData)
magicApi.SearchforId("table", "123")
magicApi.GetTable("table")
magicApi.Search("table", "column", "value")
End Sub
Thank you for your enthusiasm and support. Let the Magic API transform your B4X applications into powerful, connected experiences! 🚀✨

Please note that all the source code we sell is highly advanced and requires technical skills to use. By purchasing, you agree to the following terms and conditions:
User Responsibility:
Missing Libraries:
Refunds:
Code Distribution:
License:
Modification of Terms:
Login To Comment