0
Cart
0

    Cart is Empty!! Add some products in your Cart

Total:
0.00
View cart Check out

Product Details

Sold By
B4X Store

18

Total Items
Contact Seller
Magic API Library

⚡️ 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:

Security Measures:

  • Authentication: All requests require an API key for access control.
  • HTTPS: Encrypted communication ensures data confidentiality.
  • Input Validation: Guards against common security vulnerabilities.

Base URL:

http://example.com/api.php

Authentication Parameters:

api_key (required): Unique key for request authentication.

Available Resources:

GET /api.php

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 <=).

POST /api.php

Parameters:

  • table (required): Name of the table to create a new record.
  • Request Body: Data for the new record in JSON format.

PUT /api.php

Parameters:

  • table (required): Name of the table to update a record.
  • id (required): ID of the specific record to update.
  • Request Body: Updated data for the record in JSON format.

DELETE /api.php

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 <=).

💡 Explore Examples:

GET /api.php

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:

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

{
  "name": "John Doe",
  "age": 30,
  "email": "johndoe@example.com"
}

PUT /api.php

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

MagicApi library

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
        ' 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

Complete Example

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! 🚀✨

Mv1Mbye.png
Welcome to b4xstore

Please note that all of the source codes we are selling are very advance and needs skills to be able to use them.

1- we are not responsible if you don't know how to use them
2- we are not responsible if you modified them and caused errors.
3- we are not responsible to provide any missing libraries because most of the libraries used can be found in B4X Forum
4- NO refunds allowed at any given point.
5- The Terms and Conditions Can be changed anytime with no prior notice.

To Comment

Ratings & Reviews

5.0

To Review

Sign up to newslatter

COPYRIGHT © 2024. All Rights Reserved By B4X Store