B4A Library ✨ Magic API Library: Transform Your MySQL Database into a REST API in Just 5 Minutes! 🚀

⚡️ Unleash the API Power: Magic API for Seamless B4X Integration

🌟 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!

🚀 Advantages of Magic API:
✨ Unlock the Magic: Seamlessly integrate API functionality into your B4X applications.
✉️ Effortless CRUD Operations: Create, Read, Update, and Delete with ease, optimizing data management.
🔒 Advanced Security Measures: API key authentication, HTTPS encryption, and input validation ensure data confidentiality and integrity.
🌐 Base URL: http://example.com/api.php
💻 User-Friendly Initialization: Just upload, edit the header with your connection data, and you're ready to communicate!


🚀Usage Instructions:

1. Upload the api.php file to your server.
2. Edit the header with your connection data.
3. You're ready to communicate your app with your mobile and desktop applications.

Note: The API works fine without the library, but the library will help you communicate more easily.

💡 Explore API Documentation:

API Documentation​

Security​

The API employs several security measures to ensure the integrity and confidentiality of your data:

  • Authentication: All API requests require an API key to be included as a query parameter. This key uniquely identifies the client making the request and provides access control to the API endpoints.
  • HTTPS: Communication with the API is always encrypted over HTTPS, ensuring that data transmitted between the client and the server remains confidential.
  • Input validation: The API performs input validation and sanitization to prevent common security vulnerabilities such as SQL injection or cross-site scripting (XSS) attacks.

Base URL​

Authentication​

The API uses an API key for authentication. The API key must be included as a parameter in all requests.

Authentication Parameters​

  • api_key (required): The API key to authenticate the request.

Available Resources​

GET /api.php​

Retrieve records from a table.

Parameters​

  • table (required): The name of the table from which you want to retrieve records.
  • id (optional): The ID of the specific record you want to retrieve.
  • column and value (optional): The name of a column and its value to filter the records.
  • comparison (optional): The comparison operator to use in the search. It can be >, <, >=, or <=.

Examples​


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



POST /api.php​

Create a new record in a table.

Parameters​

  • table (required): The name of the table in which you want to create the record.

Request Body​

You must provide the data for the new record in JSON format in the request body.

Example​

POST /api.php?table=example&api_key=your_api_key


{
"name": "John Doe",
"age": 30,
"email": "[email protected]"
}

PUT /api.php​

Update an existing record in a table.

Parameters​

  • table (required): The name of the table in which the record exists.
  • id (required): The ID of the specific record you want to update.

Request Body​

You must provide the updated data for the record in JSON format in the request body.

Example​


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 /api.php​

Delete records from a table.

Parameters​

  • table (required): The name of the table from which you want to delete records.
  • id or column and value (required): You can provide the ID of the specific record you want to delete, or use a column and its value to filter the records.
  • comparison (optional): The comparison operator to use in the search. It can be >, <, >=, or <=.

Examples​


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

Remember to replace your_api_key with your actual API key.




MagicApi library
# B4X Library Documentation

## Description
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.

## Installation
1. Download the MagicApi.b4xlib library file.
2. Copy the MagicApi.b4xlib file to the additional libraries folder in your B4X development environment.

## Initialization
Before using the library methods, you need to initialize it by calling the `Initialize` method and providing the following parameters:
- `CallbackModule` (Object): the name of the callback module where the events handling API responses are located.
- `cEventname` (String): the base name for the response events.
- `urlbase` (String): the base URL of the API.
- `api_key` (String): The api key defined in the php file.

## Events
The library generates response events for each CRUD operation. These events should be implemented in the specified callback module during initialization.

### Generated Events
- `EventName_Insertmaps(m As Map, success As Boolean)`
- `EventName_Delete(tablename As String, success As Boolean)`
- `EventName_DeleteByColumn(tablename As String, success As Boolean)`
- `EventName_Update(tablename As String, success As Boolean)`
- `EventName_UpdateByColumn(tablename As String, success As Boolean)`
- `EventName_SearchforId(m As Map, success As Boolean)`
- `EventName_GetTable(x As List, success As Boolean)`
- `EventName_Search(x As List, success As Boolean)`

## Methods

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

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

end if

sub


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

end if

sub


Complete Example​


example:
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


👉 Download Magic API Now

Thank you for your enthusiasm and support. Let the Magic API transform your B4X applications into powerful, connected experiences! 🚀✨
 
Last edited:

fernando1987

Active Member
Licensed User
Take advantage and get a 30% discount on any product throughout this month with the code STORECODE30
 

fernando1987

Active Member
Licensed User
*Version 2.0 available*

**Security**


The API prioritizes security and implements various measures to safeguard the integrity and confidentiality of your data:

1. **Authentication**: To access the API, every request must include an API key as a query parameter. This key serves as a unique identifier for the client making the request and grants access control to the API endpoints.

2. **HTTPS**: All communication with the API is encrypted using HTTPS. This ensures that data transmitted between the client and the server remains confidential and protected from unauthorized access.

3. **Input Validation**: The API incorporates robust input validation and sanitization techniques. By doing so, it guards against common security vulnerabilities like SQL injection and cross-site scripting (XSS) attacks. This helps maintain the integrity of the data and protects against malicious input.

For users who have previously obtained an earlier version, they can access the store and log in to their user panel. In the "Recent Orders" section, they will find the option to view their order and download the updated Version 2.0 of the API.
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
Think about magic for
1) searching records by a part of field's value, ">", "<", ">=", "<="...
2) pagination of the output
 

fernando1987

Active Member
Licensed User
Yes, this API fulfills the following requirements:

1) **Searching records by a part of field's value, ">", "<", ">=", "<="...**: The API has the ability to search for records using comparison operators such as ">", "<", ">=", "<=", and more. This allows you to perform more specific queries and obtain results based on custom conditions.

2) **Pagination of the output**: The API supports pagination of the results, allowing you to retrieve smaller data sets and control the number of records returned in each response. This is useful when dealing with a large number of records and you want to divide them into pages for better navigation and performance.

In summary, this API provides functionalities for searching records by a part of a field's value and for paginating the results, thus meeting the mentioned requirements.

3.png
 
Last edited:

fernando1987

Active Member
Licensed User
*Version 3.0 available*

*corrections in the queries by comparison <,>,<=,>=.

*bug fixes and optimization of the api and php file

For users who have previously obtained an earlier version, they can access the store and log in to their user panel. In the "Recent Orders" section, they will find the option to view their order and download the updated Version 3.0 of the API.
 

amorosik

Expert
Licensed User
It's not clear to me what can be done with the library offered
Could you give some practical examples of what can be done using these libraries?

I'm trying to see the DOWNLOAD link but nothing appears, can you check if it's active?
 

fernando1987

Active Member
Licensed User
Hello dear, it is a file written for php8 which allows you to transform any msql database into a json api only with the connection data of the database, it also comes with a library that will facilitate communication with the api... la liberia It is paid and the link will send you to the Liberia purchase page where you can get the library and the php file
It's not clear to me what can be done with the library offered
Could you give some practical examples of what can be done using these libraries?

I'm trying to see the DOWNLOAD link but nothing appears, can you check if it's active?
 

Xfood

Expert
Licensed User
*Version 3.0 available*

*corrections in the queries by comparison <,>,<=,>=.

*bug fixes and optimization of the api and php file

For users who have previously obtained an earlier version, they can access the store and log in to their user panel. In the "Recent Orders" section, they will find the option to view their order and download the updated Version 3.0 of the API.

hi friend, your products are really great and very helpful. Will this update be integrated into this project as well?

 

Xfood

Expert
Licensed User
Hi buddy @fernando1987 ,
Have you thought about adding the ability to send and receive a bmp/jpg/png in your magicApi?
in the case, for example, of a user table, where it is entered, Name, Surname, Photo, etc.
transfer the photo, and during a select , download the photo?
Thanks for your awesome bee
 
Top